Jump to content


This topic is now archived and is closed to further replies.


Bad code?

Recommended Posts

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">
<link rel="stylesheet" type="text/css" href="lib.css">
<body bgcolor="#FFFFFF" text="#996600" link="#996600" vlink="#996600" alink="#996600">
<table width="90%" border="1" align=center bgcolor="#FFFFFF">
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
$con = mysql_connect("localhost", "username", "pass")or die('MySQL Connect Error: '.mysql_error());
$sql = "select tema,ritmo from temas order by tema";

$queryexe = mysql_query($sql);
  $tema = mysql_result($queryexe, "tema"); 
  $ritmo = mysql_result($queryexe, "ritmo");
  <td class="listas" bgcolor="#f7efde"> <?php print ("$tema"); ?></td>
  <td class="listas" bgcolor="#f7efde"> <?php print ("$ritmo"); ?></td>
<?php }
  echo "Error: " . mysql_error();
</html> [/code]
Thanks for your help!!!

Share this post

Link to post
Share on other sites
The only part of your code that is unfamiliar to me in syntax is:

[quote]$queryexe = mysql_query($sql);
  $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 '
  <td class="listas" bgcolor="#f7efde"> ' . $tema . '</td>
  <td class="listas" bgcolor="#f7efde"> ' . $ritmo . '</td>

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.


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.