flipper828 Posted January 17, 2010 Share Posted January 17, 2010 I am new to php and am having problems displaying the contents of a database on a webpage. The headings and table show up properly but the cells that are suppose to show the database content are blank. Here's my code and I truly appreciate any help I can get. <?php $adminid = $_SESSION['UGsurv_admin']; $query = "SELECT name FROM admin WHERE adminid = '$adminid'"; $result=mysql_query($query); $row=mysql_fetch_array($result, MYSQL_ASSOC); $name = $row['name']; echo "<h2>Welcome, $name</h2><br />\n"; $date = date("l, F j, Y"); echo "<h2>Today's date: $date</h2><br />\n"; echo "<h2><br />Survey Results:</h2>\n"; echo "<table width=\"100%\" cellpadding=\"1\" border=\"1\"\n"; echo "<tr><td><strong>Firm Name</strong></td><td><strong>Preferred Dates</strong></td><td><strong>Est. Number of Attendees</strong></td><td><strong>Prior Attendance?</strong></td><td><strong>Prior Topics Found Most Valuable</strong></td><td><strong>Topics of Most Interest</strong></td></tr>\n"; { $query = "SELECT survid,firmname,prefdates,estnum,attb4,comments,comments2 FROM survey ORDER BY survid"; $result = mysql_query($query); while($row=mysql_fetch_array($result, MYSQL_ASSOC)) $survid = $row['survid']; $firmname = $row['firmname']; $prefdates = $row['prefdates']; $estnum = $row['estnum']; $attb4 = $row['attb4']; $comments = $row['comments']; $comments2 = $row['comments2']; printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n" , $firmname, $prefdates, $estnum, $attb4, $comments, $comments2); if ($estnum == 0) echo " <font color=\"ff000\">No</font><br />\n"; else echo "<br />"; } echo "</table><br /><br />\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/188813-displaying-mysql-database-content-on-a-webpage/ Share on other sites More sharing options...
wildteen88 Posted January 17, 2010 Share Posted January 17, 2010 Your code should be <?php $adminid = $_SESSION['UGsurv_admin']; $query = "SELECT name FROM admin WHERE adminid = '$adminid'"; $result=mysql_query($query); $row=mysql_fetch_array($result, MYSQL_ASSOC); $name = $row['name']; echo "<h2>Welcome, $name</h2><br />\n"; $date = date("l, F j, Y"); echo "<h2>Today's date: $date</h2><br />\n"; echo "<h2><br />Survey Results:</h2>\n"; echo "<table width=\"100%\" cellpadding=\"1\" border=\"1\"\n"; echo "<tr><td><strong>Firm Name</strong></td><td><strong>Preferred Dates</strong></td><td><strong>Est. Number of Attendees</strong></td><td><strong>Prior Attendance?</strong></td><td><strong>Prior Topics Found Most Valuable</strong></td><td><strong>Topics of Most Interest</strong></td></tr>\n"; $query = "SELECT survid,firmname,prefdates,estnum,attb4,comments,comments2 FROM survey ORDER BY survid"; $result = mysql_query($query); while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { $survid = $row['survid']; $firmname = $row['firmname']; $prefdates = $row['prefdates']; $estnum = $row['estnum']; $attb4 = $row['attb4']; $comments = $row['comments']; $comments2 = $row['comments2']; printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n" , $firmname, $prefdates, $estnum, $attb4, $comments, $comments2); if ($estnum == 0) echo " <font color=\"ff000\">No</font><br />\n"; else echo "<br />"; } echo "</table><br /><br />\n"; ?> NOTE: when posting code in the forum please use the tags. Quote Link to comment https://forums.phpfreaks.com/topic/188813-displaying-mysql-database-content-on-a-webpage/#findComment-996808 Share on other sites More sharing options...
flipper828 Posted January 17, 2010 Author Share Posted January 17, 2010 I'm sorry...I'm new here too so it will take some time for me to get used to rules. Do I need to re-post it correctly? Quote Link to comment https://forums.phpfreaks.com/topic/188813-displaying-mysql-database-content-on-a-webpage/#findComment-996811 Share on other sites More sharing options...
flipper828 Posted January 17, 2010 Author Share Posted January 17, 2010 Forgive my ignorance! I see you answered my question and it works perfectly! I just didn't use brackets as I should have. Thank you soooo much. I'm looking forward to this board in the future! Quote Link to comment https://forums.phpfreaks.com/topic/188813-displaying-mysql-database-content-on-a-webpage/#findComment-996819 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.