Impaginare risultati
-
Ho provato a buttare giù un piccolo pezzo di codice che forse dovrebbe risolvere il tuo problema.
//Da inserire prima del WHILE $riga = 1; $out = ""; //... //Da sostituire al precedente ECHO if($riga == 1) $out .= "<tr>"; else if($riga >= 1) { $out .= " <td align='center' height=60> <a class='link' href='scheda.php?ccode=$data[ccode]$linkstring' target='_blank'>$thumb</a><br> <a class='link' href='result.php?ccode=$data[ccode]$linkstring' target='_blank'> <b><font size=2>$data[mk]</font><br>$data[str]<br>$data[mo]</b></a> </td>"; $riga++; } else if($riga == 3) { $out .= "</tr>"; $riga = 1; } echo $out;Ciao!
-
Ciao Sups,
eccomi qui, scusa per il ritardo ma sono rientrata solo oggi. Grazie per la risposta!
Ma dovrebbe doventare così il codice?<? if($numitems > 0) { $link = mysql_connect($dbhost, $dbuser, $dbpass); $query .= " ORDER BY updated DESC LIMIT $startitem, $perpage"; //echo "$query<br><br>"; // TEST $result = mysql_db_query($dbname, $query, $link);   $n = 1; $riga = 1; $out = ""; while($data = mysql_fetch_array($result)) { // check to see if there is an image to display if($data[numimages]) { $query = "SELECT thumb FROM $dbimg WHERE ccode='$data[ccode]' ORDER BY id DESC LIMIT 1"; $image = mysql_db_query($dbname, $query, $link); $image = mysql_fetch_array($image); $thumb = "<img src='thumbs/$image[thumb]' border=0>"; } else { $thumb = "<img src='nophoto.gif' border=0>"; } if(!($n % 2)) { $bg = "class='fill_light'"; } else { $bg = ''; }   if($riga == 1) $out .= "<tr>"; else if($riga >= 1) { $out .= " <td align='center' height=60> <a class='link' href='scheda.php?ccode=$data[ccode]$linkstring' target='_blank'>$thumb</a><br> <a class='link' href='result.php?ccode=$data[ccode]$linkstring' target='_blank'> <b><font size=2>$data[mk]</font><br>$data[str]<br>$data[mo]</b></a> </td>"; $riga++; } else if($riga == 3) { $out .= "</tr>"; $riga = 1; } echo $out; $n++; } mysql_close($link); } else { echo "<tr><td class='text' height=100 colspan=6 align='center' valign='middle'> <font class='hint'>Sorry no result.</font><br> </td></tr>"; } ?>Perchè sè è così... non mi mostra alcun risultato

Dove ho sbagliato?
Grazie ancora!
-
Rileggendo meglio le tue indicazioni, forse è più "corretto" così... tra virgolette perchè sicuramente ho sbagliato qualcosa...
<? // display results if($numitems > 0) { $link = mysql_connect($dbhost, $dbuser, $dbpass); $query .= " ORDER BY updated DESC LIMIT $startitem, $perpage"; //echo "$query<br><br>"; // TEST $result = mysql_db_query($dbname, $query, $link);   $riga = 1; $out = "";   while($data = mysql_fetch_array($result)) { // check to see if there is an image to display if($data[numimages]) { $query = "SELECT thumb FROM $dbimg WHERE ccode='$data[ccode]' ORDER BY id DESC LIMIT 1"; $image = mysql_db_query($dbname, $query, $link); $image = mysql_fetch_array($image); $thumb = "<img src='thumbs/$image[thumb]' border=0>"; } else { $thumb = "<img src='common/nophoto.gif' border=0>"; }   if($riga == 1) $out .= "<tr>"; else if($riga >= 1) { $out .= " <td align='center' height=60> <a class='link' href='scheda.php?ccode=$data[ccode]$linkstring' target='_blank'>$thumb</a><br> <a class='link' href='scheda.php?ccode=$data[ccode]$linkstring' target='_blank'> <b><font size=2>$data[mk]</font><br>$data[str]<br>$data[mo]</b></a> </td>"; $riga++; } else if($riga == 3) { $out .= "</tr>"; $riga = 1; } echo $out;   mysql_close($link); } else { echo "<tr><td class='text' height=100 colspan=6 align='center' valign='middle'> <font class='hint'>Sorry no result.</font><br> </td></tr>"; } ?>Ora mi dà questo errore
Parse error: syntax error, unexpected T_ELSERiferito a questo punto "} else {" verso la fine.
Aiutooooo

Notte a tutti
-
-
Prova a mettere $riga = 1; e $out = ""; sopra if($numitems > 0)
Mentre l'errore è dovuto al fatto che ELSE viene associato ad un WHILE e non ad IF.Metti in questo modo:
//... mysql_close($link); } } else { echo "<tr> ...Ti consigli anche di utilizzare le tabulazioni ed i rientri per il codice, semplifica di molto il riconoscimento dello scope delle variabili, la presenza di parentesi e l'associazione tra funzioni.
Es. codice non identato
if(true) echo "true"; else echo "false";E' la stessa cosa scrivere
if(true) echo "true"; else echo "false";Ma la seconda è visibilmente più semplice da accettare, specialmente se il codice è molto lungo.
Ciao!
-
Grazie della risposta e soprattutto sui consigli, fanno sempre piacere

Ho fatto come dici tu, spostando le due righe in alto e modificando la sintassi come da te suggerito ma ricevo una sfilza di erorri
Warning: mysql_close(): 10 is not a valid MySQL-Link resource
Warning: mysql_db_query(): 10 is not a valid MySQL-Link resource
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
ecc ecc

Warning: mysql_close(): 10 is not a valid MySQL-Link resourceWarning: mysql_close(): 10 is not a valid MySQL-Link resource
-
-
-
-
Eccomi qui, incollo il codice della pagenda.
Così modificato non dà alcun errore ma la query non dà alcun risultato, anche se dovrebbe!
Grazie
<? require '/global.php'; require '/config/config.php'; // create link string that will be attached to each vehicle link $linkstring = "&startitem=$startitem&startpage=$startpage&endpage=$endpage¤t=$current&category=$category&make=$make&model=$model&condition=$condition"; // get info from database $link = mysql_connect($dbhost, $dbuser, $dbpass); $query = "SELECT updated FROM $dbvin ORDER BY updated DESC"; $result = mysql_db_query($dbname, $query, $link); $result = mysql_fetch_array($result); //$date = date('l d M, Y \a\l\l\e\ \o\r\e g:i a', $result[updated]); $query = "SELECT COUNT(*) FROM $dbvin"; $result = mysql_db_query($dbname, $query, $link); $result = mysql_fetch_array($result); $count = $result[0]; $result = mysql_db_query($dbname, "SELECT email, phone FROM $dbcfg", $link); $contact = mysql_fetch_array($result); mysql_close($link); // build search query string if neccessary if($condition || $make || $model || $stock || $body || $fuel) { // build query string $query = "SELECT * FROM $dbvin WHERE"; if($condition) { $query .= " condition='$condition' AND"; } if($make) { $query .= " make='$make' AND"; } if($model) { $query .= " model='$model' AND"; } if($stock) { $query .= " stock='$stock' AND"; } if($body) { $query .= " body='$body' AND"; } if($fuel) { $query .= " fuel='$fuel'"; } // trim extra AND if neccessary if(substr($query, strlen($query)-4, 4) == ' AND') { $query = substr($query, 0, strlen($query)-4); } } else { $query = "SELECT * FROM $dbvin"; } // get number of results $link = mysql_connect($dbhost, $dbuser, $dbpass); $result = mysql_db_query($dbname, $query, $link); if(mysql_num_rows($result)) { $numitems = mysql_num_rows($result); } else { $numitems = 0; } mysql_close($link); ?> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="css/default.css" rel="stylesheet" type="text/css"> <script language='JavaScript' src='functions.js'></script> </head> <body> <table class='trim' width=770 border=0 bgcolor=white cellpadding=3 cellspacing=0> <tr> <td colspan=5> <table width='100%' border=0 cellpadding=0 cellspacing=0> <td><a class='link' href="javascript:history.back()"><img src='common/indietro.gif' border=0 align='absmiddle'> Indietro </a></td> </table> </td> </tr> <tr> <td width='100%' colspan=6> <table width='100%' border=0 cellpadding=0 cellspacing=0> <tr class='text'> <? if($numitems > 0) { $numpages = ceil($numitems / $perpage); // THE TOTAL NUMBER OF PAGES if(!$startitem) { $startitem = 0; } // FIGURE startitem AND enditem VALUES if($startitem + $perpage > $numitems) { $enditem = $numitems; } else { $enditem = $startitem + $perpage; } if(!$startpage) { $startpage = 1; } // FIGURE startpage VALUE if(!$endpage) { // FIGURE endpage VALUE if($numpages > $numlinks) { $endpage = $numlinks; } else { $endpage = $numpages; } } } else { //echo "<td align='center'>no results error GOES HERE?</td>"; } ?> </table> </td> </td> <td rowspan="21"> </td> <tr class='fill'><td height=1 colspan=10><!-- LINE --></td></tr> <? // display results $riga = 1; $out = ""; if($numitems > 0) { $link = mysql_connect($dbhost, $dbuser, $dbpass); $query .= " ORDER BY updated DESC LIMIT $startitem, $perpage"; //echo "$query<br><br>"; // TEST $result = mysql_db_query($dbname, $query, $link); while($data = mysql_fetch_array($result)) { // check to see if there is an image to display if($data[numimages]) { $query = "SELECT thumb FROM $dbimg WHERE ccode='$data[ccode]' ORDER BY id DESC LIMIT 1"; $image = mysql_db_query($dbname, $query, $link); $image = mysql_fetch_array($image); $thumb = "<img src='thumbs/$image[thumb]' border=0>"; } else { $thumb = "<img src='common/nophoto.gif' border=0>"; } if($riga == 1) $out .= "<tr>"; else if($riga >= 1) { $out .= " <td align='center' height=60> <a class='link' href='scheda.php?ccode=$data[ccode]$linkstring' target='_blank'>$thumb</a><br> <a class='link' href='scheda.php?ccode=$data[ccode]$linkstring' target='_blank'> <b><font size=2>$data[make]</font><br>$data[stereo]<br>$data[model]</b></a> </td>"; $riga++; } else if($riga == 3) { $out .= "</tr>"; $riga = 1; } echo $out; } mysql_close($link); } else { echo "<tr><td class='text' height=100 colspan=6 align='center' valign='middle'> <font class='hint'>Sorry no result.</font><br> </td></tr>"; } ?> -
-
Niente

Non dà errori ma non scrive più nemmeno "Sorry no results"....
Niente....
La pagina originale funziona e mette i risultati uno per riga, ma da quando stiamo provando con le varie modifiche o dà errore o nessun errore ma non mostra nulla :bho:
Hai qualche idea in proposito?
Grazie ancora
Sara -
Ho visto che nel codice manca una chiusara TR
<td width='100%' colspan=6> <table width='100%' border=0 cellpadding=0 cellspacing=0> <tr class='text'> <-- SI APRE UN TR <? if($numitems > 0) { $numpages = ceil($numitems / $perpage); // THE TOTAL NUMBER OF PAGES if(!$startitem) { $startitem = 0; } // FIGURE startitem AND enditem VALUES if($startitem + $perpage > $numitems) { $enditem = $numitems; } else { $enditem = $startitem + $perpage; } if(!$startpage) { $startpage = 1; } // FIGURE startpage VALUE if(!$endpage) { // FIGURE endpage VALUE if($numpages > $numlinks) { $endpage = $numlinks; } else { $endpage = $numpages; } } } else { //echo "<td align='center'>no results error GOES HERE?</td>"; } ?> </table> </tr> <--- E SI CHIUDE QUI, Sostituito </td> </td> <td rowspan="21"> </td>Poi prova a mettere:
$riga = 1;
$out = "Debug di OUT";per vedere se scrive qualche cosa.
-
-
-
-
-
-
Sups
Dato che la query, cioè la richiesta al DB, è limitata ad un risultato (LIMIT 1), non è possibile ricavare più di una foto, di conseguenza è impossibile affiancarle.Eccomi, scuami il ritardo ma sono stata via
Ho provato ad eliminare "LIMIT 1" ma è tutto come prima :bho:
Anche perchè, se volessi limitare a un solo risultato, comunque dovrebbe mostrarmelo no? e invece nulla.
Come ti dicevo l'output della query ora è questoDebug di OUT Debug di OUT Debug di OUT Debug di OUT Debug di OUT Debug di OUT Debug di OUT Debug di OUT Debug di OUTNon capisco dov'è il problema. Con la pagina originale funzionante mi mostra tutto correttamente ma uno solo per riga, è così difficile mostrarne 3 per riga?

Aiutatemi ragazzi!!!

-
Sups
Il problema potrebbe essere nelle query che non restituiscono i giusti risultati, oppure nella struttura del codice html generato.
Potresti postere il codice html generato per vedere se è presente qualche traccia della tabella generata da $out.Ciao Sups,
in poche parole devo postarti tutto il codice della pagina?
Grazie!
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi