godsent Posted December 12, 2008 Share Posted December 12, 2008 I've been thinking how can i get information from sql table into array. My code looks like this: function loadMenu() { $menu_name = array("Home", "Register", "Login", "test" ); $menu_locations = array("?home", "?register", "?login", "?test"); $menu_count = sizeof($menu_name); print "<li class='first'><a href='$menu_locations[0]'> $menu_name[0] </a></li>"; for ($i = 1; $i < $menu_count; ++$i) { print "<li><a href='$menu_locations[$i]'> $menu_name[$i]</a></li>"; } } and I'm wondering how can i get "Home, Register, Login, Test" from SQL into array $menu_name. Link to comment https://forums.phpfreaks.com/topic/136662-from-sql-to-array/ Share on other sites More sharing options...
waterssaz Posted December 12, 2008 Share Posted December 12, 2008 Little confused what you are trying to achieve here. Are you basically wanting to store your navigation options in a mysql table and then dynamically populate an array with this information to then display as you wish on your web page? :-) Link to comment https://forums.phpfreaks.com/topic/136662-from-sql-to-array/#findComment-713569 Share on other sites More sharing options...
godsent Posted December 12, 2008 Author Share Posted December 12, 2008 yes i want to store in sql name's of menu's Link to comment https://forums.phpfreaks.com/topic/136662-from-sql-to-array/#findComment-713614 Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 First of all you need to make a table in your database. Do you have access to phpMyAdmin or something similar? Link to comment https://forums.phpfreaks.com/topic/136662-from-sql-to-array/#findComment-713739 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 lets assume he does because I am wondering the same thing. how to make an array when you dont know what the variables are going to be or how many there are going to be can you help. Link to comment https://forums.phpfreaks.com/topic/136662-from-sql-to-array/#findComment-713754 Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 Well I'd expect you'd have some idea of what you were adding to your database, but like this; Lets imagine your table was; id INT(11) auto-increment Primary Key number TINYINT(2) $yourArray = array(1,2,3,4,5,6,7); $query = "INSERT INTO `yourtable` (`number`) VALUES "; for($i=1;$i<=count($yourArray);$i++){ $query .= "({$yourArray[$i]}), "; } $query = substr($query,0,-2); $result = mysql_query($query) or die(mysql_error()); Please note I haven't included any validation or database connection Link to comment https://forums.phpfreaks.com/topic/136662-from-sql-to-array/#findComment-713800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.