scarhand Posted November 22, 2007 Share Posted November 22, 2007 why isnt this working? when i press the submit button it tries to go to the new page but it seems like it just keeps loading something over and over and over the $myid variable is an integer like 23, or whatever. <?php if (!empty($_FILES['file']['tmp_name'])) { while ($row = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE id='$myid'"))) { $oldphoto = $row['myphoto']; echo $oldphoto; } } ?> Link to comment https://forums.phpfreaks.com/topic/78442-solved-while-loop-inside-if-empty_filesfiletmp_name/ Share on other sites More sharing options...
Orio Posted November 22, 2007 Share Posted November 22, 2007 Because you are lazy. In your while loop the query is being re-run over and over... Should be: <?php if (!empty($_FILES['file']['tmp_name'])) { $result = mysql_query("SELECT * FROM users WHERE id='$myid'"); while ($row = mysql_fetch_array($result)) { $oldphoto = $row['myphoto']; echo $oldphoto; } } ?> Orio. Link to comment https://forums.phpfreaks.com/topic/78442-solved-while-loop-inside-if-empty_filesfiletmp_name/#findComment-396947 Share on other sites More sharing options...
cooldude832 Posted November 22, 2007 Share Posted November 22, 2007 add error reporting to the query <?php <?php if (!empty($_FILES['file']['tmp_name'])) { $q = "Select * from `users` where id = '".$myid."'"; $result = mysql_query($q) or die(mysql_error()."<br />".$q); if(mysql_num_rows($result) >0){ while ($row = mysql_fetch_array($result)) { $oldphoto = $row['myphoto']; echo $oldphoto; } } else{ echo "No Records found."; } } ?> Link to comment https://forums.phpfreaks.com/topic/78442-solved-while-loop-inside-if-empty_filesfiletmp_name/#findComment-396985 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.