radar Posted April 12, 2009 Share Posted April 12, 2009 Alright for the life of me i can't figure this out... I've got a table in my database, it's got 2 cells in it they are name and price Now, what I am trying to do is select everything from the database, which is easy. Though I need the output to be something like this. array ( name1 = price1, name2 = price2, name3 = price3, name4 = price4 ) with of course the names and prices being whats in the select. I just have no clue how to do it. Link to comment https://forums.phpfreaks.com/topic/153696-solved-foreach-while-etc-what-to-use-and-how/ Share on other sites More sharing options...
nankoweap Posted April 12, 2009 Share Posted April 12, 2009 have you tried something like? ... $item = array(); while ($row = mysqli_fetch_array($result)) { $item[$row['name']] = $row['price']; } ... jason Link to comment https://forums.phpfreaks.com/topic/153696-solved-foreach-while-etc-what-to-use-and-how/#findComment-807728 Share on other sites More sharing options...
radar Posted April 12, 2009 Author Share Posted April 12, 2009 I had figured this out prior to your posting.. it's REAL similar... $prices = mysql_query("SELECT name, price FROM table"); $prices = $aws->sql_prices_array($prices); function sql_prices_array($query1) { while ($erray = mysql_fetch_array($query1, MYSQL_ASSOC)) { $mda[$erray["name"]] = $erray["price"]; } return $mda; } Link to comment https://forums.phpfreaks.com/topic/153696-solved-foreach-while-etc-what-to-use-and-how/#findComment-807731 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.