cooldude832 Posted October 10, 2007 Share Posted October 10, 2007 I have this <?php connectSQL(); $events_old = "events"; $q = "select * from `".$events_old."` Order by Event_Year Desc"; $r = mysql_query($q) or die(mysql_error()); echo mysql_num_rows($r)." Records Found<br />"; $i = 0; while($row = mysql_fetch_array($r)){ $date = $row['Event_Year']."/".$row['Event_Month']."/".$row['Event_Day']; if($date == "//"){$date = "";} $q = "Insert Into `".E_TABLE."` (CreatorID, Type, Date_start, Location, About) Values( '1', '".$row['Event_Type']."', '".$date."', '".$row['State']."', \"".$row['Event_Comments']."\")"; $r = mysql_query($q) or die(mysql_error().$q); $i++; echo "Record: ".$i."<br />"; } ?> It returns 267 records found, but only adds the first row any ideas? Also it only does the loop for the first one as it shows Record: 1 and that is it it doesn't error, but only loops once instaed of the 267 times it should. Quote Link to comment https://forums.phpfreaks.com/topic/72688-solved-whilerow-mysql_fetch-only-doing-first-row/ Share on other sites More sharing options...
darkfreaks Posted October 10, 2007 Share Posted October 10, 2007 because i=0 so it only returns once? Quote Link to comment https://forums.phpfreaks.com/topic/72688-solved-whilerow-mysql_fetch-only-doing-first-row/#findComment-366525 Share on other sites More sharing options...
pocobueno1388 Posted October 10, 2007 Share Posted October 10, 2007 Maybe your overwriting the past queries since you are using the same variable names. Try changing the $q and $r inside the loop to different letters. Quote Link to comment https://forums.phpfreaks.com/topic/72688-solved-whilerow-mysql_fetch-only-doing-first-row/#findComment-366526 Share on other sites More sharing options...
marcus Posted October 10, 2007 Share Posted October 10, 2007 Hmm, looks clean. Try swapping the echo with the increment. @poco: That shouldn't be a problem, they get overwritten if they're redefined. Quote Link to comment https://forums.phpfreaks.com/topic/72688-solved-whilerow-mysql_fetch-only-doing-first-row/#findComment-366529 Share on other sites More sharing options...
pocobueno1388 Posted October 10, 2007 Share Posted October 10, 2007 @poco: That shouldn't be a problem, they get overwritten if they're redefined. Exactly, and they are being redefined in his script. Quote Link to comment https://forums.phpfreaks.com/topic/72688-solved-whilerow-mysql_fetch-only-doing-first-row/#findComment-366531 Share on other sites More sharing options...
cooldude832 Posted October 10, 2007 Author Share Posted October 10, 2007 bingo on the $r repeat. I made it $q2 $r2 in the while loop I guess i just wasn't thinking doing a lot of that lately. Quote Link to comment https://forums.phpfreaks.com/topic/72688-solved-whilerow-mysql_fetch-only-doing-first-row/#findComment-366533 Share on other sites More sharing options...
marcus Posted October 10, 2007 Share Posted October 10, 2007 @poco: That shouldn't be a problem, they get overwritten if they're redefined. Exactly, and they are being redefined in his script. I've never had that problem and I do that a lot. Quote Link to comment https://forums.phpfreaks.com/topic/72688-solved-whilerow-mysql_fetch-only-doing-first-row/#findComment-366534 Share on other sites More sharing options...
cooldude832 Posted October 10, 2007 Author Share Posted October 10, 2007 now the annoying part of fixing the magic quotes/slashes is on Quote Link to comment https://forums.phpfreaks.com/topic/72688-solved-whilerow-mysql_fetch-only-doing-first-row/#findComment-366540 Share on other sites More sharing options...
pocobueno1388 Posted October 10, 2007 Share Posted October 10, 2007 Check your phpinfo() to see if magic_quotes_gpc is on or off. If it is on, do this: ini_set('magic_quotes_gpc', 'off'); Quote Link to comment https://forums.phpfreaks.com/topic/72688-solved-whilerow-mysql_fetch-only-doing-first-row/#findComment-366546 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.