Jump to content

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

Edited by Barand
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.