Jump to content

[SOLVED] Cant Re-Use MYSQL Array


greenday

Recommended Posts

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.