Fluoresce Posted December 4, 2012 Share Posted December 4, 2012 Hi, guys. I haven't been here for years! It's changed so much. I am trying to get back into PHP, which I have almost completely forgotten! Please help me with the following question. After selecting my data, how can I get 'name' to appear in my h1 element? <?php $conn = mysql_connect("localhost", "user", "pass") or die ("Unable to connect"); mysql_select_db ("database", $conn) or die ("Unable to select database"); $sql = "SELECT name, head, thumb, des FROM people WHERE catnum = 1 ORDER BY date DESC"; $rslts = mysql_query($sql, $conn) or die ("Unable to run query"); $num_rows = mysql_num_rows($rslts); echo "<h1>WANT NAME HERE ($num_rows)</h1>"; while ($row = mysql_fetch_assoc($rslts)) { echo "<ul>"; echo "<li>{$row['head']}</li>"; echo "<li>{$row['thumb']}</li>"; echo "<li>{$row['des']}</li>"; echo "</ul>"; } mysql_close($conn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/271603-problem-with-selecting-from-database-and-displaying-data/ Share on other sites More sharing options...
Barand Posted December 4, 2012 Share Posted December 4, 2012 (edited) $rslts = mysql_query($sql, $conn) or die ("Unable to run query"); $num_rows = mysql_num_rows($rslts); $row = mysql_fetch_assoc($rslts); echo "<h1>{$row['name']} ($num_rows)</h1>"; do { echo "<ul>"; echo "<li>{$row['head']}</li>"; echo "<li>{$row['thumb']}</li>"; echo "<li>{$row['des']}</li>"; echo "</ul>"; } while ($row = mysql_fetch_assoc($rslts)); Edited December 4, 2012 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/271603-problem-with-selecting-from-database-and-displaying-data/#findComment-1397551 Share on other sites More sharing options...
Fluoresce Posted December 4, 2012 Author Share Posted December 4, 2012 Thanks, Barand! It seems to be working well! Quote Link to comment https://forums.phpfreaks.com/topic/271603-problem-with-selecting-from-database-and-displaying-data/#findComment-1397611 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.