Visualizzazione dei risultati da 1 a 5 su 5

Discussione: problema con while

  1. #1

    problema con while

    E' una tabella news...uso un mysql_fetch_row per elencare le news che hanno la stessa data. All'interno di queste news ci possono essere più di un link. Es. la news 1 ha 2 links, la news 3 links e via dicendo.
    Se una volta trovata la news, nel campo links c'è 1, vuol dire che quella news ha dei link e quindi fa a farmi un select nella tabella links, avendo come punto di riferimento l'id della news.
    Il problema è che non son capace a fare il ciclo..in modo tale che ad ogni news mi associ i suoi links..

    vi posto il codice

    Codice PHP:
    $query_news mysql_query("SELECT * FROM News WHERE data = '$data' ORDER BY id DESC"$connection); // la variabile $connection mi fa la connessione al database

    while(list($id$weekday$data$ora$id_area$titolo$autore,
    $testo$immagine$imm_align$links$commenti) = mysql_fetch_row($query_news))
    {

    if (
    $links == 1// è dove controllo se la news ha dei links

    $query_links mysql_query("SELECT * FROM link_news WHERE id_news = '$id' ORDER BY id ASC"$connection); // mi cerca i link che hanno come collegamento l'id della news

    while($row_link mysql_fetch_array($query_linksMYSQL_ASSOC)) 
    {
    $link "» [url="$row_link[link]"]Link collegamento esterno[/url]
    "
    ;
    }
    }

    $titolo nl2br(stripslashes($titolo));
    $testo nl2br(stripslashes($testo));
    $ora2 "$ora";
    $split_ora explode(":",$ora2);


    print(
    "<tr height=6><td height=6 align=left valign=middle></td>
                                        </tr>
                                        <tr>
                                          <td align=left valign=middle class=titolo_news>
    $titolo</td>
                                        </tr>
                                        <tr>
                                          <td align=left valign=middle class=data_news_bottom>
    $weekday$split_data[2] $mese$split_data[0]$split_ora[0]:$split_ora[1] | <span class=style3>by <a href=mailto:nanni@manicomix.it>Nanni</a></span> </td>
                                        </tr>
                                        <tr height=6>
                                          <td height=6 align=left valign=middle></td>
                                        </tr>
                                        <tr>
                                          <td align=left valign=middle><table width=99%  border=0 align=center cellpadding=7 cellspacing=1 bgcolor=#41403B>
                                            <tr>
                                              <td bgcolor=#F2F0E8 class=testo_news><p align=justify>
    $immagine $testo </td>
                                            </tr>
                                          </table>
                                          
                                          </td>
                                        </tr>
                                                                            <tr height=6>
                                                                              <td height=6 align=left valign=middle></td>
                                        </tr>
                                                                            <tr>
                                          <td align=left valign=middle><table width=100%  border=0 cellspacing=0 cellpadding=0>
                                            <tr>
                                              <td align=left valign=top class=link_news>
    $link</td>
                                              <td align=right valign=top class=link_news>:: [b][url="
    commenti.php>Commenti</a>[/b]"]Stampa News[/url][/b] :: </td>
                                            </tr>
                                            <tr height=10 >
                                              <td height=10 colspan=2 align=left valign=top></td>
                                            </tr>
                                             <tr height=1>
                                              <td height=1 colspan=2 align=left valign=top background=imgs/filo2.gif></td>
                                            </tr>
                                            <tr height=5>
                                              <td height=5 colspan=2 align=left valign=top></td>
                                            </tr>
                                          </table></td>
                                        </tr>"
    );
                                        
                                        } 

    Alla fine il problema è che mi stampa solo 1 link, anche se ce ne sono più di uno

  2. #2
    scusa.. non ho ben capito.....

    while($row_link = mysql_fetch_array($query_links, MYSQL_ASSOC))

    {

    $link = "&raquo; Link collegamento esterno
    ";

    }

    qui che cosa vorresti fare?
    non è che vuoi appendere ed invece di appendere riassegni?

  3. #3
    Infatti ho fatto na boiata...hehe..dovevo usare un altro mysql_fetch_row

    sono troppo arrugginito in php

  4. #4
    ma sto facendo un casino

    guarda questa pagina

    http://www.manicomix.it/news.php

    Vengono elencate 2 news...
    la prima news dovrebbe avere 2 link..quella sotto 1 solo

    Le 2 tabelle sono queste:
    • News
    • Link_news


    Nella tabella news c'è un campo di nome links..se il valore è 1 si fa un select con id = news, nella tabella Link_news.
    Prende tutti i links che hanno quell'id e me li mette nel primo ciclo while.

  5. #5
    arghhh ce l'ho fatta!

    ecco il codice finale

    Codice PHP:



    $query_news 
    mysql_query("SELECT * FROM News WHERE data = '$data' ORDER BY id DESC",  $connection);

    while(list(
    $id$weekday$data$ora$id_area$titolo$autore$testo$immagine$imm_align$links$commenti) = mysql_fetch_row($query_news))
    {
    if (
    $immagine != "") { $immagine "<img src=imgs/news/$immagine hspace=8 vspace=2 border=1 align=$imm_align>"; } else { $immagine ""; }

    $titolo nl2br(stripslashes($titolo));
    $testo nl2br(stripslashes($testo));
    $ora2 "$ora";
    $split_ora explode(":",$ora2);


    print(
    "<tr height=6><td height=6 align=left valign=middle></td>
                                        </tr>
                                        <tr>
                                          <td align=left valign=middle class=titolo_news>
    $titolo</td>
                                        </tr>
                                        <tr>
                                          <td align=left valign=middle class=data_news_bottom>
    $weekday$split_data[2] $mese$split_data[0]$split_ora[0]:$split_ora[1] | <span class=style3>by <a href=mailto:nanni@manicomix.it>Nanni</a></span> </td>
                                        </tr>
                                        <tr height=6>
                                          <td height=6 align=left valign=middle></td>
                                        </tr>
                                        <tr>
                                          <td align=left valign=middle><table width=99%  border=0 align=center cellpadding=7 cellspacing=1 bgcolor=#41403B>
                                            <tr>
                                              <td bgcolor=#F2F0E8 class=testo_news><p align=justify>
    $immagine $testo </td>
                                            </tr>
                                          </table>
                                          
                                          </td>
                                        </tr>
                                                                            <tr height=6>
                                                                              <td height=6 align=left valign=middle></td>
                                        </tr>
                                                                            <tr>
                                          <td align=left valign=middle><table width=100%  border=0 cellspacing=0 cellpadding=0>
                                            <tr><td align=left valign=top class=link_news>"
    );
                                            
                                            if (
    $links == 1) {
    $query_links mysql_query("SELECT * FROM link_news WHERE id_news = '$id' ORDER BY id_news DESC"$connection);
    while(list(
    $id$id_news$nome_link$link$target) = mysql_fetch_row($query_links)) {
    echo 
    "&raquo; [url="$link"]$nome_link[/url]
    "
    ;
    }
    }
                                                
                                            print (
    "</td><td align=right valign=top class=link_news>:: [b][url="commenti.php>Commenti</a>[/b]"]Stampa News[/url][/b] :: </td>
                                            </tr>
                                            <tr height=10 >
                                              <td height=10 colspan=2 align=left valign=top></td>
                                            </tr>
                                             <tr height=1>
                                              <td height=1 colspan=2 align=left valign=top background=imgs/filo2.gif></td>
                                            </tr>
                                            <tr height=5>
                                              <td height=5 colspan=2 align=left valign=top></td>
                                            </tr>
                                          </table></td>
                                        </tr>"
    );



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.