• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

PHP Results Not Showing

RedWolf

Golden Member
I'm getting the number of rows but I can't get the username (or any other field) to write to the page. No errors are being thrown.


$db=mysql_connect("server", "user", "password");
mysql_select_db("resnet",$db);
$result= mysql_query("select * from wireless",$db);
$num_results= mysql_num_rows($result);
echo $num_results;
while ($myrow = mysql_fetch_row($result));
{
echo $myrow["username"];
}
 
do a print_r on $myrow and see what comes out. you may be addressing the "username" array var incorrectly or it may be all in caps or somethign wierd.
 
Your while statement is pretty screwy looking. In my opinion you shouldnt be setting a variable in a while condition. Plus, I believe mysql_fetch_row will only give you one row and your query is definately going to return many more.... so even if the while statement was working, it would probably turn into an infinate loop

do something like this instead:
 
Everytime the mysql_fetch_array($result) is called, it will keep incrementing which result it returns? I never knew that. But my code is still shorter and less dangerous 😉. I tend to avoid while loops just because they're pretty easy to screw up.
 
Got it to work with both of those and figured out what was wrong with mine.

while ($myrow = mysql_fetch_row($result));

should be

while ($myrow = mysql_fetch_row($result))

Now, I'm trying to get it to pull ONLY the last row. However, when I try to change the sql query to:

select top 1 ID, IPAddress from wireless order by ID desc

I get the following error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in W:\html\secure\resnet\wireless\dhcp.php on line 10

It would be easy enough to change the loop but shouldn't this work? I generally work with ASP and things seem to translate fairly well but not everything. Also, does anyone have any suggestions for a web site that would aid in transitioning to PHP from ASP?

Thanks for all the help.
 
Back
Top