greenday Posted October 14, 2008 Share Posted October 14, 2008 I have a sql array, but i can only out it in a while loop once. If try to put the same result in another while loop, the results are blank. Has anyone had this problem before? My php / mysql is within javascript, but i dont think this has anything to do with it. Here is the code : <script type="text/javascript"> //<![CDATA[ var map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.addControl(new GScaleControl()); map.setCenter(new GLatLng(<?php echo $row_mapsize['lat']; ?>, <?php echo $row_mapsize['lon']; ?>), <?php echo $row_mapsize['zoom']; ?>, G_NORMAL_MAP); // Creates a marker whose info window displays the given number function createMarker(point, number) { var marker = new GMarker(point); // Show this markers index in the info window when it is clicked var html = number; GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);}); return marker; }; <?php $regionid=$HTTP_GET_VARS['id']; mysql_select_db($database_admin, $admin); $query_bizlist = "SELECT * FROM wineries where region = '$regionid' AND "; If($_GET['tastings'] == 'full') { $tastings = $_GET['tastings']; $query_bizlist =$query_bizlist. "full_desc != ' ' AND "; } If($_GET['tastings'] == 'openpublic') { $tastings = $_GET['tastings']; $query_bizlist =$query_bizlist. "open_public_tastings = '1' AND "; } If($_GET['bordeaux_style_blends'] >= '1') { $bordeaux_style_blends = $_GET['bordeaux_style_blends']; $query_bizlist =$query_bizlist. "bordeaux_style_blends = '1' AND "; } $sql = rtrim($query_bizlist," AND "); $bizlist = mysql_query($sql, $admin) or die(mysql_error()); $row_bizlist = mysql_fetch_assoc($bizlist); $totalRows_bizlist = mysql_num_rows($bizlist); while ($row_bizlist = mysql_fetch_assoc($bizlist)) { echo "var point = new GLatLng(" . $row_bizlist['lat'] . "," . $row_bizlist['lon'] . ");\n"; echo "var marker = createMarker(point, '<div id=\"mapWindow\" ><strong><a href=details.php?id=".$row_bizlist['id']." > ".$row_bizlist['name']." </a></strong><br /><form method=post name=form1 action=$editFormAction><input type=submit value=Add to My Wine Trail><input type=hidden name=wtentryid value=><input type=hidden name=username value=".$user->data['username']."> <input type=hidden name=wineryid value=".$row_bizlist['id']."><input type=hidden name=MM_insert value=form1></form> <br/> ".$row_bizlist['address']." <br /> Ph: ".$row_bizlist['phone']." <br/> <a target=_blank href= ".$row_bizlist['website']." > ".$row_bizlist['website']." </a> <br /><a href=mailto:".$row_bizlist[email]." >Email Winery</a> <br />Cellar Hours: ".$row_bizlist[cellar_hours]." </div>');\n"; echo "map.addOverlay(marker);\n"; echo "\n"; } ?> //]]> </script> Quote Link to comment https://forums.phpfreaks.com/topic/128319-solved-cant-re-use-mysql-array/ Share on other sites More sharing options...
Barand Posted October 14, 2008 Share Posted October 14, 2008 you have to reset the internal pointer to the beginning if the resultset with mysql_data_seek($result, 0); Quote Link to comment https://forums.phpfreaks.com/topic/128319-solved-cant-re-use-mysql-array/#findComment-664757 Share on other sites More sharing options...
greenday Posted October 14, 2008 Author Share Posted October 14, 2008 Hi thanks for your quick reply. I have never come across mysql_data_seek before. I looked it up, but still cant work out where to put it in the code, please could you show me? Also, could you tell me why I need to do this on this occassion, as i have never had to do this before? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/128319-solved-cant-re-use-mysql-array/#findComment-664781 Share on other sites More sharing options...
Barand Posted October 14, 2008 Share Posted October 14, 2008 When you call mysql_query() it returns a resultset with an internal pointer pointing the first record. Each call to a mysql_fetch_xxxx() returns the next record in the resultset until its pointer reaches the end, and then it returns false. Further calls return false unless to move the internal result pointer back to the start. Alternatively you can requery the database. Also, could you tell me why I need to do this on this occassion, as i have never had to do this before? Can you post all the code you've ever written before so I can answer that one? EDIT. BTW, the seek needs to go before your second attempt to loop throught the data and after you have looped through it the first time. Quote Link to comment https://forums.phpfreaks.com/topic/128319-solved-cant-re-use-mysql-array/#findComment-664853 Share on other sites More sharing options...
greenday Posted October 16, 2008 Author Share Posted October 16, 2008 Thanks for your help. I managed to get it working with your help. I will post all the code i have ever written in a new thread for you Quote Link to comment https://forums.phpfreaks.com/topic/128319-solved-cant-re-use-mysql-array/#findComment-667512 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.