473,386 Members | 1,835 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,386 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 1267

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? ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.