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

    Lettura dati query e foreach

    Ciau a tutti ^^
    Codice PHP:
    <?
    $user 
    "SELECT * FROM pages WHERE nickname = '$x'";
    $risultato mysql_query($user) or die("Query fallita: " mysql_error() );

    while (
    $row=mysql_fetch_array($risultato)) 

        
    $str= array($row["musicvideo1"],
        
    $row["musicvideo2"],
        
    $row["musicvideo3"],
        
    $row["musicvideo4"],
        
    $row["musicvideo5"],
        
    $row["musicvideo6"],
        
    $row["musicvideo7"],
        
    $row["musicvideo8"],
        
    $row["musicvideo9"],
        
    $row["musicvideo10"]);
        
    $data= array($row["mvtitle1"],
        
    $row["mvtitle2"],
        
    $row["mvtitle3"],
        
    $row["mvtitle4"],
        
    $row["mvtitle5"],
        
    $row["mvtitle6"],
        
    $row["mvtitle7"],
        
    $row["mvtitle8"],
        
    $row["mvtitle9"],
        
    $row["mvtitle10"]);
    ?>
    <div class="title_menu_hdr_dx">
    My Music Video</div>
    <div class="my_contents_dx"><? if ($row['musicvideo1'] == ""){ echo $errore_box; } else { foreach($str as $key => $string) {
    echo 
    "<a href=\"".$str."\">".$data."</a>
    "
    ;
    <? 
    //while chiuso
    ?>
    In poche parole, dalla lettura dei dati con la query vorrei che lo script mi stampasse questo codice a schermo:
    " <? echo $row[mvtitle]; ?> "
    e questo per tutti i dati (dovrebbero risultare alla fine 10 link). Ho provato a mettere un foreach, anche se nn sn molto sicuro che vada bene. Difatto stampa a schermo la parola "Array" 10 volte :|
    Però non è detto che tutti i campi siano riempiti... nel caso nn fossero riempiti e nn ci fosse nessun controllo mi stamperebbe una cosa del genere:

    Come si può indicare che deve stampare solo i campi pieni?
    Grazie in anticipo
    Webmaster of Crystal~Memories

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    dopo forech aggiungi un if

    codice:
    if ($str!="" && $data!="") {
      echo("<a href=\"".$str."\">".$data."</a>
    ");
    }
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  3. #3
    Ho aggiunto questo if, ma la pagina rimane bianca (pare che nessuna operazione viene svolta!) e nn succede nulla (neanke errore di sintassi)
    Webmaster of Crystal~Memories

  4. #4
    Mi correggo, la pagina è eseguita, ma rimangono comunque 10 link "array"
    Webmaster of Crystal~Memories

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    591
    prova con:
    Codice PHP:
    echo "<a href=\"".$str[$key]."\">".$data[$key]."</a>
    "

    o

    Codice PHP:
    echo "<a href=\"".$string."\">".$data[$key]."</a>
    "

    PS: io non userei variabili chiamate string non si sa mai..

  6. #6
    Grazie mille *_* ora funziona, thanks
    Webmaster of Crystal~Memories

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.