Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php not looping with DB information correctly

Status
Not open for further replies.

LoveOpnSrc

Programmer
Feb 6, 2008
14
US
Hi,

I am not sure why this is not working the way I think it should. My issue is I can not display number of items in the database correctly. When I do the
Code:
Select count(*) from DanceInfo
in the database it returns 3, this is correct. However, when I try and display it in PHP, at best I can get this to loop twice. How can I make it display 3 ?
Here is my code.

Code:
//Query String
$rsCount = mysql_query("Select count(*) from tableDanceInfo");
//Get actual count
$num_rows = mysql_num_rows($rsCount);
//Display 
 $i = 0;
 while($i <= $num_rows)
  {
   print"There are : ";echo($num_rows);print"<br>";
  $i++;
  }

Thank you in advance...
3 am time for bed now... :)
 
I do not see what you are trying to do, but you are asking for a row count twice. First, you ask for a count in SQL. The answer to that is ONE row containing the rowcount.

Next, you ask how many rows your SQL query has returned. That is off course always 1: the row containing the rowcount.

Hope you are awake now...

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
You query will only ever return 1 row: the count, nothing more.

And your while loop starting at 0 will run twice (for $i=0 and $i=1) before stopping. Printing the count value twice.

However this has nothing to do with whatever the actual count query returns. It can return 25 and it still going to print only twice the way you set it up.








----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks for the insight.

I have a database that every year gets updated with 12 new records in it. I want to count how many records are in the database. Then loop through the number so this year it'll be 12 and check for a date value, so see when it is to be displayed to the website. that is my goal. How can I achieve this?

Thanks in advance again...
 
I'm not entirely sure I understand, what does the number of records have to do with the date?

Perhaps an example may illustrate the problem and help us understand.






----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top