davt55 Posted February 13, 2011 Share Posted February 13, 2011 I cannot retrieve my records from my table, neither can I display them on my website. I do not even get any errors when I run the script on my site. Any help or tips would be greatly appreciated. My current php script is: // connection to database server $db_selected = mysql_select_db('database1', $dbc); if (!$db_selected) { die ('Can\'t use database1 : ' . mysql_error()); } $query = "SELECT * FROM chesstable ORDER BY chapter, lastname"; $result = mysql_query($query) or die('Could not connect' . mysql_error()); echo mysql_num_rows($result); If (!$result) { $message = 'Invalid query: ' . mysql_error(); $message = 'Whole query: ' . $query; die ($message); } while($row = mysql_fetch_assoc($result)) { echo $row['firstname'] . " " . $row['lastname'] . $row['chapter']; } mysql_free_result($result); mysql_close($dbc); ?> Link to comment https://forums.phpfreaks.com/topic/227535-mysql_fetch_assoc-and-echo-problem/ Share on other sites More sharing options...
ruddie Posted February 13, 2011 Share Posted February 13, 2011 Well, I normally never use mysql_fetch_assoc, since I always get troubled with it.. I would simply do this: $numOfRows = mysql_num_rows($result); $i = 0; while ( $i < $numOfRows ) { mysql_result($result,$i,"firstname"); mysql_result($result,$i,"lastname"); mysql_result($result,$i,"chapter"); // echo stuff } Although it might seem inefficient, it always worked for me, so that's fine. Link to comment https://forums.phpfreaks.com/topic/227535-mysql_fetch_assoc-and-echo-problem/#findComment-1173736 Share on other sites More sharing options...
Jessica Posted February 13, 2011 Share Posted February 13, 2011 | | V (errors) Link to comment https://forums.phpfreaks.com/topic/227535-mysql_fetch_assoc-and-echo-problem/#findComment-1173738 Share on other sites More sharing options...
ruddie Posted February 13, 2011 Share Posted February 13, 2011 | | V (errors) Is that about my post? Link to comment https://forums.phpfreaks.com/topic/227535-mysql_fetch_assoc-and-echo-problem/#findComment-1173740 Share on other sites More sharing options...
Jessica Posted February 13, 2011 Share Posted February 13, 2011 | | V (errors) Is that about my post? *sigh* No, it was my response to the Op saying he gets no errors. Link to comment https://forums.phpfreaks.com/topic/227535-mysql_fetch_assoc-and-echo-problem/#findComment-1173797 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.