473,224 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

having problem displaying results

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
4 1261

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
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
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
Forgot the link to mysql_fetch_array(). Here it is:

www.php.net/mysql_fetch_array

Zilla
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David | last post by:
I am retreiving information from a database and it works ok, but its rather a lot and I like to limit each web page to 10 rows of data, then put the next ten on a new web page, probably with a...
6
by: Francisco | last post by:
I have this question: I have a simple search to a db, something like: "select description from games where year = '1990'" suppose I get 300 results, I would like to display this in pages of 30...
4
by: Bryan | last post by:
I have a results table that is 5 columns wide. the recordset is returned with 48 items. I have no problem displaying 5 per row until I hit the last row where i get a ADODB.Field error '80020009' ...
4
by: Tim T | last post by:
Hi, I have a stored procedure executing a search and an asp.net page displaying the results in a datagrid. The datagrid has paging on it, I am using Visual Studio.NET and can't see any option...
0
by: dipper | last post by:
I have a dataset with several tables. Now i want to create different dataviews displaying results from some of the tables. I manage to create a view displaying 1 table, but how do i create a view...
2
by: cabellm | last post by:
Hi, I am creating a web feedback form that has a both a checkbox and listbox on it that are both databound to a database. I have been researching all day and have found multiple answers for...
1
by: Brave | last post by:
I have MS Access databases that are viewed via ASP pages made in Frontpage. I have two issues that have the same problem. 1: When someone views database results on one of my webpages, and...
13
by: David W. Fenton | last post by:
I've been struggling the last two days with something I thought was very easy, which is to open a web page with a form on it and populate the form with data passed in a query string (either POST or...
3
by: Nightcrawler | last post by:
I have a website that does the following: 1. it accepts a keyword through a textbox in the UI 2. once the submit button is clicked it goes out and spiders a few websites using the keyword...
1
by: Crombam | last post by:
Hi to all, After searching the net for a couple of hours I just have to ask the question. How can I close a report with a subform (Pivot Chart) when this Pivot Chart is having no data? ...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.