Forum Moderators: coopster
<?php
include('connect.php');
$query = "SELECT * FROM products WHERE SlideNumber > '0' ORDER BY SlideNumber";
$result = mysql_query($query);
if (!$result)
{
die("Could Not Query Database: <br />".mysql_error());
}
while ($row = mysql_fetch_array($result)){
echo "?category=".$row["Category"]."&which=".$row["ID"];
}
?>
The query works fine and the echo statement looks as it should although I'm only using it view the results. Since I have a column in my database that stores the slideshow sequence number of a product, if I were to put the results of my query into an javascript array I think a javascript function (similar to the one that rotates the images) can also handle the hyperlink. Does anyone have any advice on this? Thanks.
Here's where I've left off:
<?php
include('connect.php');
$query = "SELECT * FROM products WHERE SlideNumber > '0' ORDER BY SlideNumber ASC";
$result = mysql_query($query);
if (!$result)
{
die("Could Not Query Database: <br />".mysql_error());
}
$counter = 0;
$dynalinks = array();
while ($row = mysql_fetch_array($result)){
$dynalinks[$counter] = "?category=".$row["Category"]."&which=".$row["ID"];
$counter++;
}
?>
I've got it! Thanks to the code I found in the link pasted above.
Here's the solution at work in my code for any of you who might run into a similar problem:
<script type="text/javascript">
dynalink = new Array();
<?php
for($i=0;$i<count($dynalinks); $i++){
echo "dynalink[$i]='".$dynalinks[$i]."';\n";
}
?>
for(i=0;i<dynalink.length;i++);
</script>
[edited by: dreamcatcher at 8:47 am (utc) on Feb. 13, 2008]
[edit reason] no urls as per T.O.S [webmasterworld.com].Thanks [/edit]
<?php
$arr = array(
'red' => 2,
'blue' => 5,
'green' => array('purple' => 2)
);
echo '<script type="text/javascript">'.PHP_EOL;
echo 'var arr = '.json_encode($arr).';'.PHP_EOL;
echo 'alert(arr.red * arr.blue + arr.green.purple);'.PHP_EOL; // 12
echo '</script>';
?>
I think that may be a bit beyond me right now (not using 5.2), but thanks for the tip. I found something else that might be cleaner than what I've got going but I'm not sure how to catch the array in js yet.
echo 'new Array('.implode(', ', $dynalinks).')';