shepps_ Posted August 3, 2007 Share Posted August 3, 2007 ok i have a dynamic drop-down menu going on. However, the links that i want to appear in the drop-down list (javascript array) are in the php database. here's the javascript code: var menu1=new Array() menu1[0]='<a href="link.php">name</a>' menu1[1]='<a href="link.php">name</a>' menu1[2]='<a href="link.php">name</a>' menu1[3]='<a href="link.php">name</a>' and i want to do basically get info from my database, so i tried this but failed: <? while ($d = mysql_fetch_object($res)) { ?> menu1[<?=$x?>]='<a href="products.php?de=<?=$d->did?>"><?=$d->dname?></a>' <? } ?> any ideas? all replies are appreciated Quote Link to comment Share on other sites More sharing options...
shepps_ Posted August 3, 2007 Author Share Posted August 3, 2007 what i meant by this part.. and i want to do basically get info from my database, so i tried this but failed: <? while ($d = mysql_fetch_object($res)) { ?> menu1[<?=$x?>]='<a href="products.php?de=<?=$d->did?>"><?=$d->dname?>[/url]' <? } ?> is, i want to build a javascript array by cycling through the enteries in the database. so say if there were 5 enteries in there, the while loop would generate menu1[0]...menu1[4], each containing a link in them. really need this urgently, any advice would be a great help Quote Link to comment Share on other sites More sharing options...
php_tom Posted August 7, 2007 Share Posted August 7, 2007 Assuming that your SQL is correct, etc, I would try: <?php for($i=0;$i<mysql_num_rows($res);$i++) { $row = mysql_fetch_assoc($res); echo "menu1[".$i."] = '<a href=\"products.php?de=".$row['did']."\">".$row['dname']."</a>"; } ?> Does this help? Quote Link to comment 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.