Jump to content

Problem With Selecting From Database And Displaying Data


Fluoresce

Recommended Posts

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);
?>


$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));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.