jeva39 Posted September 24, 2006 Share Posted September 24, 2006 I try to load records into a Table but repeat in the two colums the same field and only the first record. No rows for the rest of records... For example, the first record is "A la candela" and the rhythm is "Merengue". The output is "A la candela" "A la candela" And repeat this record forever You can check this at: http://www.prolatin.com/php/jv_mysql2.php This is the code: [code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Pruebas</title> <link rel="stylesheet" type="text/css" href="lib.css"> </head> <body bgcolor="#FFFFFF" text="#996600" link="#996600" vlink="#996600" alink="#996600"> <table width="90%" border="1" align=center bgcolor="#FFFFFF"> <tr> <td> <?php ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); $con = mysql_connect("localhost", "username", "pass")or die('MySQL Connect Error: '.mysql_error()); mysql_select_db("jv"); $sql = "select tema,ritmo from temas order by tema"; $queryexe = mysql_query($sql); while(mysql_fetch_row($queryexe)) { $tema = mysql_result($queryexe, "tema"); $ritmo = mysql_result($queryexe, "ritmo"); ?> <tr> <td class="listas" bgcolor="#f7efde"> <?php print ("$tema"); ?></td> <td class="listas" bgcolor="#f7efde"> <?php print ("$ritmo"); ?></td> </tr> <?php } echo "Error: " . mysql_error(); ?> </td> </tr> </table> </body> </html> [/code] Thanks for your help!!! Link to comment https://forums.phpfreaks.com/topic/21894-bad-code/ Share on other sites More sharing options...
WendyLady Posted September 24, 2006 Share Posted September 24, 2006 The only part of your code that is unfamiliar to me in syntax is:[quote]$queryexe = mysql_query($sql); while(mysql_fetch_row($queryexe)) { $tema = mysql_result($queryexe, "tema"); $ritmo = mysql_result($queryexe, "ritmo");[/quote]I usually would write this for mysql_fetch_row:[quote]$queryexe = mysql_query($sql);while(list($tema, $ritmo) = mysql_fetch_row($result)){echo ' <tr> <td class="listas" bgcolor="#f7efde"> ' . $tema . '</td> <td class="listas" bgcolor="#f7efde"> ' . $ritmo . '</td> </tr>'; }[/quote]Maybe this will help? I know it is irrational, but I always avoid escaping out of php in the middle of a query because it always seems to cause problems for me. Mostly, though, try the while(list() syntax.Wendy Link to comment https://forums.phpfreaks.com/topic/21894-bad-code/#findComment-97799 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.