By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,768 Members | 1,227 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,768 IT Pros & Developers. It's quick & easy.

having problem displaying results

P: n/a
Hey here is my code - The number of rows are being displayed that are
currently in the database (3) but when i try to get the data out it
isn't being displayed, showing merely the just the rows with the
lines.... can you help me? thanks!

<?
require_once ('mysqyl_connect.php');

$query="SELECT * FROM CLIENT_INFO";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Client List</center></b><br><br>";

$i=0;
while ($i < $num) {

$first=mysql_result($result,$i,"first_name");
$last=mysql_result($result,$i,"last_name");
$mobile=mysql_result($result,$i,"email");

echo "<b>$last_name</b><br>E-mail: $email<br><hr><br>";

$i++;
}

?>

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

wrw[three] wrote:
Hey here is my code - The number of rows are being displayed that are
currently in the database (3) but when i try to get the data out it
isn't being displayed, showing merely the just the rows with the
lines.... can you help me? thanks!

<?
require_once ('mysqyl_connect.php');

$query="SELECT * FROM CLIENT_INFO";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
You close the database connection here, after that how do you expect to
retrieve any information?
echo "<b><center>Client List</center></b><br><br>";

$i=0;
while ($i < $num) {

$first=mysql_result($result,$i,"first_name");
$last=mysql_result($result,$i,"last_name");
$mobile=mysql_result($result,$i,"email");

echo "<b>$last_name</b><br>E-mail: $email<br><hr><br>";

$i++;
}

?>


The better way of doing this would be:
<?
$q="SELECT * FROM CLIENT_INFO";
$rs=mysql_query($q);
$num=mysql_numrows($rs);
if ($num > 0) {
echo "<b><center>Client List</center></b><br><br>\n";
while ($rw = mysql_fetch_assoc($rs))
echo '<b>' . $row['last_name'] . '</b><br>E-mail: ' .
$row['email'] . "<br><hr><br>\n";
}
?>

Basically, you're $result (my $rs) contains a pointer to the
information, not the information. You still have to retrieve it from
the database, which is what the while loop does.

Ken

Jul 17 '05 #2

P: n/a
hmmm.... still isn't working.... I'm getting the three rows, but no
data is being put into them? any other suggestions??!? thanks for your
help!

Jul 17 '05 #3

P: n/a
wrw[three] wrote:
hmmm.... still isn't working.... I'm getting the three rows, but no
data is being put into them? any other suggestions??!? thanks for your
help!


In these lines you save the data in $first, $last and $mobile:

$first=mysql_result($result,$i,"first_name");
$last=mysql_result($result,$i,"last_name");
$mobile=mysql_result($result,$i,"email");

and in this line you use variables equal to the field names:

echo "<b>$last_name</b><br>E-mail: $email<br><hr><br>";

Try using the variables you save the data in ;-)

echo "<b>$last</b><br>E-mail: $mobile<br><hr><br>";

But i agree with Ken that his solution is better and the php manual also
advises you to use this because it is much quicker. Look here:

www.php.net/mysql_result

Zilla
Jul 17 '05 #4

P: n/a
Forgot the link to mysql_fetch_array(). Here it is:

www.php.net/mysql_fetch_array

Zilla
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.