Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
This seems like a simple PHP MySQL problem, but it has me stumped.
The page has the following php code:
<?
$query = "SELECT * FROM test";
$result = mysql_query($query);
$totalrows = mysql_num_rows($result);
print "$totalrows";
?>The test table has 20 rows, so the page should just display the number '20'. But it returns blank. The interesting thing is that this code knocks out anything else on the page and it all returns blank. Anyone see what I'm doing wrong?
croftstorm.net

about the blank, maybe the server setting sets "blank" on error. Some hosting companies're doing this. Not a place for developers.
Your query is quite simple. As long as the connection is correct [ mysql_connect() or mysql_pconnect() ], the db correctly selected [ mysql_select_db() ], and the table `test` exists, it should be working.
---
Fubar

A few things:
1) Eitehr you are not connecting to the database or you did not include the code in your post.
2) You should always include error handling in your database action: connecting to the database, running a query, etc. I prefer NOT to use "die" in the final production version (instead handling errors gracefully). But, there's no problem using it during development.
Based upon your code above I think the problem is definitely a problem with the query. Use this instead and report back what the error is:
<?php
$query = "SELECT * FROM test";
$result = mysql_query($query) or die (mysql_error());
$totalrows = mysql_num_rows($result);
print "$totalrows";
?>Michael J

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |