tet3828 Posted February 2, 2008 Share Posted February 2, 2008 If someone would kindly take the time out to explain to me litterarly why the code below displays nothing... $row = mysql_fetch_array($result); echo "".$row['geoLoc']."<br>"; whereas this code shows my result ??? while($row = mysql_fetch_array($result)) { echo "".$row['geoLoc']."<br>"; } I'd be extremely thankful. Just trying to grasp all these concepts. Quote Link to comment https://forums.phpfreaks.com/topic/89018-is-using-msql_fetch_array-without-a-while-loop-possible/ Share on other sites More sharing options...
ryeman98 Posted February 2, 2008 Share Posted February 2, 2008 If you're grabbing data from a specific row of data, then you don't need a while loop. If you're grabbing data from multiple rows, then you'll need a while loop as it will keep going through the data until there is nothing left for it to pull out. Hope this helps! Quote Link to comment https://forums.phpfreaks.com/topic/89018-is-using-msql_fetch_array-without-a-while-loop-possible/#findComment-455878 Share on other sites More sharing options...
trq Posted February 2, 2008 Share Posted February 2, 2008 The first example should display the current record, providing $result is a valid result resource. Using a while loop just iterates through a series of records. Quote Link to comment https://forums.phpfreaks.com/topic/89018-is-using-msql_fetch_array-without-a-while-loop-possible/#findComment-455879 Share on other sites More sharing options...
pocobueno1388 Posted February 2, 2008 Share Posted February 2, 2008 Without a while loop it is only going to show the first result. Is the "GeoLoc" field in your DB empty for the first result? You might want to check that out. Quote Link to comment https://forums.phpfreaks.com/topic/89018-is-using-msql_fetch_array-without-a-while-loop-possible/#findComment-455881 Share on other sites More sharing options...
tet3828 Posted February 2, 2008 Author Share Posted February 2, 2008 thanks thus far. but how would I echo out only the third row? Quote Link to comment https://forums.phpfreaks.com/topic/89018-is-using-msql_fetch_array-without-a-while-loop-possible/#findComment-456293 Share on other sites More sharing options...
pocobueno1388 Posted February 2, 2008 Share Posted February 2, 2008 thanks thus far. but how would I echo out only the third row? If all you want is the third row, why not just adjust your query? I'm assuming you have some sort of auto-incremented row, we will call that "id". SELECT * FROM table_name WHERE id=3 Quote Link to comment https://forums.phpfreaks.com/topic/89018-is-using-msql_fetch_array-without-a-while-loop-possible/#findComment-456295 Share on other sites More sharing options...
monkeytooth Posted February 2, 2008 Share Posted February 2, 2008 SELECT * FROM table_name WHERE id=3 Will only pull the record that has ID number 3, not the third row each time.. if you want to call upon the 3rd row everytime then LIMIT 3,1 to your query should work may be wrong on the 3,1 part.. but the idea is to have it query the DB starting at the 3rd row and return 1 result Quote Link to comment https://forums.phpfreaks.com/topic/89018-is-using-msql_fetch_array-without-a-while-loop-possible/#findComment-456299 Share on other sites More sharing options...
pocobueno1388 Posted February 2, 2008 Share Posted February 2, 2008 Well, I was logically thinking that the row with an ID number of 3 WOULD be the third row. I suppose it could be different. Quote Link to comment https://forums.phpfreaks.com/topic/89018-is-using-msql_fetch_array-without-a-while-loop-possible/#findComment-456301 Share on other sites More sharing options...
monkeytooth Posted February 2, 2008 Share Posted February 2, 2008 No i understand the logic, I do the same thing myself as you mentioned.. it's just a thought though. I don't really know where I was going with my comment lol, was something that just poped into mind and I typed it out posted it prior to thinking logically about it. The only downside is if this person doesnt have ID's or ends up deleting the line with that ID for a new one.. Again I dunno where I was going with it though lol, didn't mean to come across as underminding.. just giving up an alternative in case he didnt have ID's i guess.. Quote Link to comment https://forums.phpfreaks.com/topic/89018-is-using-msql_fetch_array-without-a-while-loop-possible/#findComment-456309 Share on other sites More sharing options...
pocobueno1388 Posted February 2, 2008 Share Posted February 2, 2008 No, I completely agree with you. The method you suggested would probably be better. That way you get the third row whether the data is corrupted or not in the DB. So that was a great thought Quote Link to comment https://forums.phpfreaks.com/topic/89018-is-using-msql_fetch_array-without-a-while-loop-possible/#findComment-456331 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.