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 Link to comment https://forums.phpfreaks.com/topic/63134-getting-php-info-in-javascript-array/ 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 Link to comment https://forums.phpfreaks.com/topic/63134-getting-php-info-in-javascript-array/#findComment-314647 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? Link to comment https://forums.phpfreaks.com/topic/63134-getting-php-info-in-javascript-array/#findComment-317795 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.