Jump to content


Photo

Bad code?


  • Please log in to reply
1 reply to this topic

#1 jeva39

jeva39
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 24 September 2006 - 09:52 PM

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....p/jv_mysql2.php


This is the 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>

Thanks for your help!!!

#2 WendyLady

WendyLady
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 24 September 2006 - 10:26 PM

The only part of your code that is unfamiliar to me in syntax is:

$queryexe = mysql_query($sql);
while(mysql_fetch_row($queryexe))
    {
  $tema = mysql_result($queryexe, "tema"); 
  $ritmo = mysql_result($queryexe, "ritmo");


I usually would write this for mysql_fetch_row:

$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>';
}


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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users