cp_rua Posted July 7, 2010 Share Posted July 7, 2010 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 $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>"; }} ?> Quote Link to comment https://forums.phpfreaks.com/topic/206955-only-one-field-appears-in-second-and-subsequent-records/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 7, 2010 Share Posted July 7, 2010 $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... Quote Link to comment https://forums.phpfreaks.com/topic/206955-only-one-field-appears-in-second-and-subsequent-records/#findComment-1082220 Share on other sites More sharing options...
cp_rua Posted July 7, 2010 Author Share Posted July 7, 2010 Thank you very much !!! Quote Link to comment https://forums.phpfreaks.com/topic/206955-only-one-field-appears-in-second-and-subsequent-records/#findComment-1082226 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.