MartinaL Posted March 8, 2006 Share Posted March 8, 2006 I want to display some rows from a MySQL database in a php page in the following format;Each row should be displayed one after the other like this. column 1 is called Date, 2 is called Heading and 3 is called Content-----Date - HeadingContentI have tried setting this up with the following piece of code but nothing is being displayed on the screen at all;[code]<?php $dbhost = 'localhost'; $dbuser = 'dhopec'; $dbpass = '<<MY PASSWORD>>'; $dbname = 'dhopec_com_-_content'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $query_string = "select Date, Heading, Content from news"; $result = mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<table><tr><td colspan="2"><b>Database Output</b></td></tr>"; $i=0; while ($i < $num) { $Date=mysql_result($result,$i,"Date"); $Heading=mysql_result($result,$i,"Heading"); $Content=mysql_result($result,$i,"Content"); echo "<tr><td><b>$Date</td><td>$Heading</td></tr><tr><td colspan="2">$Content</td></tr></table>"; $i++; } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/4399-displaying-data-from-mysql-db-problems/ Share on other sites More sharing options...
greycap Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=352717:date=Mar 7 2006, 09:02 PM:name=MartinaL)--][div class=\'quotetop\']QUOTE(MartinaL @ Mar 7 2006, 09:02 PM) [snapback]352717[/snapback][/div][div class=\'quotemain\'][!--quotec--][/quote]$result = mysql_query($query);Shouldn't that be mysql_query($query_string) in your example?Also, any one of those mysql functions can fail. You should be checking for that and handling it every time. Quote Link to comment https://forums.phpfreaks.com/topic/4399-displaying-data-from-mysql-db-problems/#findComment-15266 Share on other sites More sharing options...
MartinaL Posted March 8, 2006 Author Share Posted March 8, 2006 I updated but still no luck, nothing at all is displayed on the page.I'm fairly new to PHP so to check each line to see if it fails how do I do this? Quote Link to comment https://forums.phpfreaks.com/topic/4399-displaying-data-from-mysql-db-problems/#findComment-15299 Share on other sites More sharing options...
greycap Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=352757:date=Mar 7 2006, 10:51 PM:name=MartinaL)--][div class=\'quotetop\']QUOTE(MartinaL @ Mar 7 2006, 10:51 PM) [snapback]352757[/snapback][/div][div class=\'quotemain\'][!--quotec--]I updated but still no luck, nothing at all is displayed on the page.I'm fairly new to PHP so to check each line to see if it fails how do I do this?[/quote]The other problem is this:$num=mysql_numrows($result);Theres no such thing as mysql_numrows() its mysql_num_rows(). This will make $num = null which is why that loop is never entered.Dont you have error messages turned on? Quote Link to comment https://forums.phpfreaks.com/topic/4399-displaying-data-from-mysql-db-problems/#findComment-15302 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.