Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    Union select da problemi

    Ciao ragazzi cosa sbaglio in questa query? in pratica mi stampa solamente Nick1, mentre tutti gli altrri provenienti da UNION risultano vuori (ma non è così).

    Codice PHP:
    $quem "SELECT Nick as Nick1 FROM torneo_yes  WHERE Posizione = '1' 
    UNION SELECT Nick as Nick2 FROM torneo_yes  WHERE Posizione = '2' 
    UNION SELECT Nick as Nick3 FROM torneo_yes  WHERE Posizione = '3' 
    UNION SELECT Nick as Nick4 FROM torneo_yes  WHERE Posizione = '4' 
    UNION SELECT Nick as Nick5 FROM torneo_yes  WHERE Posizione = '5' 
    UNION SELECT Nick as Nick6 FROM torneo_yes  WHERE Posizione = '6' 
    UNION SELECT Nick as Nick7 FROM torneo_yes  WHERE Posizione = '7' 
    UNION SELECT Nick as Nick8 FROM torneo_yes  WHERE Posizione = '8' 
    UNION SELECT Nick as Nick9 FROM torneo_yes  WHERE Posizione = '9' 
    UNION SELECT Nick as Nick10 FROM torneo_yes  WHERE Posizione = '10' 
    UNION SELECT Nick as Nick11 FROM torneo_yes  WHERE Posizione = '11'
    UNION SELECT Nick as Nick12 FROM torneo_yes  WHERE Posizione = '12'  
    UNION SELECT Nick as Nick13 FROM torneo_yes  WHERE Posizione = '13' 
    UNION SELECT Nick as Nick14 FROM torneo_yes  WHERE Posizione = '14' 
    UNION SELECT Nick as Nick15 FROM torneo_yes  WHERE Posizione = '15' 
    UNION SELECT Nick as Nick16 FROM torneo_yes  WHERE Posizione = '16'"
    ;
    $rem mysql_query($quem$db) or die(mysql_error());
    $trem mysql_fetch_array($rem); 

    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  2. #2
    Utente di HTML.it L'avatar di neida
    Registrato dal
    Feb 2005
    Messaggi
    1,478
    Che senso ha sfruttare tante volte la clausola UNION per estrarre risultati dalla stessa tabella quando potresti risolvere con la sola istruzione IN, senza creare poi tutti quegli ALIAS che potresti gestire più facilmente tramite php.

    codice:
    SELECT Nick FROM torneo_yes WHERE Posizione IN(1, 2, 3, 4, 5, 6 ... )
    selezioni i Nick con posizione da 1 fino a 16 e al momento dell'estrazione poi creati le variabili dedicate ad ogni singolo nick.

  3. #3
    Utente di HTML.it L'avatar di Il_Drugo
    Registrato dal
    May 2006
    Messaggi
    1,220
    Se i valori di posizione sono consecutivi puoi usare una semplice comparazione numerica:

    Codice PHP:
    SELECT Nick FROM torneo_yes WHERE Posizione 17 

  4. #4
    Originariamente inviato da Il_Drugo
    Se i valori di posizione sono consecutivi puoi usare una semplice comparazione numerica:

    Codice PHP:
    SELECT Nick FROM torneo_yes WHERE Posizione 17 
    il problema è che non devo stamparli a while ma in parti diverse della pagina
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  5. #5
    Utente di HTML.it L'avatar di Il_Drugo
    Registrato dal
    May 2006
    Messaggi
    1,220
    non vedo il problema....


    Codice PHP:
    $sql "SELECT Nick FROM torneo_yes WHERE Posizione < 17 ORDER BY Posizione";
    $result mysql_query($sql);
    $j=0;
    while(
    $row[$j] = mysql_fetch_array($result)) { $j++; }

    // li stampi dove e quando vuoi
    echo $row[1]['Nick'];
    echo 
    $row[2]['Nick'];
    echo 
    $row[3]['Nick'];
    echo 
    $row[4]['Nick'];
    echo 
    $row[5]['Nick'];
    echo 
    $row[6]['Nick'];
    echo 
    $row[7]['Nick'];
    ...... 

  6. #6
    Originariamente inviato da Il_Drugo
    non vedo il problema....


    Codice PHP:
    $sql "SELECT Nick FROM torneo_yes WHERE Posizione < 17 ORDER BY Posizione";
    $result mysql_query($sql);
    $j=0;
    while(
    $row[$j] = mysql_fetch_array($result)) { $j++; }

    // li stampi dove e quando vuoi
    echo $row[1]['Nick'];
    echo 
    $row[2]['Nick'];
    echo 
    $row[3]['Nick'];
    echo 
    $row[4]['Nick'];
    echo 
    $row[5]['Nick'];
    echo 
    $row[6]['Nick'];
    echo 
    $row[7]['Nick'];
    ...... 

    mito..
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.