Jump to content

Only one field appears in second and subsequent records


cp_rua

Recommended Posts

I have a small piece of code to retrieve information from a db and display. The first record is fine but for every other record, only my first field displays. Can any one help please?

 

Thank you :confused:

 

$newsauthor='author';

$newsdate='date';

 

mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');

mysql_select_db($dbname);

 

$query = 'SELECT * FROM ' . $usertable;

$result = mysql_query($query);if($result) {

 

    while($row = mysql_fetch_array($result)){

echo    "<b>";

echo    "<font size=2 face=verdana>";

        echo $heading= $row[$yourfield];

echo    "</b>    posted by ";

echo  "  ";

        echo $newsauthor= $row[$newsauthor];

echo  "  on ";

echo $newsdate= $row[$newsdate];

echo    "<br>";

echo    "<br>";

echo    $newscontent=$row[$newscontent];

echo    "<br>";

echo    "<br>";

echo    "<br>";

 

                                            }}

?>

 

$newsauthor='author';

$newsdate='date';

 

^^^ you are using those two variables to hold the $row[......] index names, but you are overwriting those variables in the loop, so they won't hold valid index names after the first time through the loop.

 

If you were developing and debugging php code in a system with error_reporting set to E_ALL and display_errors set to ON, you would get some error messages concerning the invalid index names that would have pointed you to the cause of the problem.

 

Edit: And since this is not a mysql problem, moving thread to the php coding forum...

 

Archived

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

×
×
  • Create New...

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.