Jump to content

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...

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.