loxfear Posted May 20, 2014 Share Posted May 20, 2014 nothing gets put into the select list <?php include 'sqlconnect.php'; $data = array(); while ($row = mysqli_fetch_assoc($result)) { $data[$row['id']] = array( 'title' => $row['title'], 'pris' => $row['pris'], ); } ?> <select name="country"> <option value="">-----------------</option> <?php foreach($data as $key => $value): echo '<option value="'.$key.'">'.$value.'</option>'; //close your tags!! endforeach; ?> </select> how do i get this to work-? Quote Link to comment Share on other sites More sharing options...
loxfear Posted May 20, 2014 Author Share Posted May 20, 2014 im getting the data from my sql server, putting it into an array and then i want the selection list to show the array Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted May 20, 2014 Share Posted May 20, 2014 Does your real code have a query? As the code stands, $result is undefined. Have you tried turning on all PHP errors? To do that, you could add the following to your PHP script: <?php //REPORT ALL PHP ERRORS error_reporting(E_ALL); ini_set('display_errors', 1); ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 20, 2014 Share Posted May 20, 2014 (edited) Assuming $result is a valid MySQL result set (with records) you would get crap for output. In this loop you are storing the records into a multi-dimensional array with the id as the index and then TWO values in the sub-array. $data = array(); while ($row = mysqli_fetch_assoc($result)) { $data[$row['id']] = array( 'title' => $row['title'], 'pris' => $row['pris'], ); } You then loop through that array as follows: foreach($data as $key => $value): echo '<option value="'.$key.'">'.$value.'</option>'; //close your tags!! endforeach; $value with be the subarray - but you are trying to echo it out. Do you want to echo out 'title' or 'pris' or some concatenation of the two? Edited May 20, 2014 by Psycho Quote Link to comment Share on other sites More sharing options...
loxfear Posted May 20, 2014 Author Share Posted May 20, 2014 what i need is an array with arrays inside, i want to be able to select the arrays inside the array, and when that is selected i want the data in that to be shown,but for now, i need the arrays to be shown in the select list menu Quote Link to comment Share on other sites More sharing options...
Solution fastsol Posted May 20, 2014 Solution Share Posted May 20, 2014 You would need to tell it which item of the array you want to echo, so either of these I guess echo '<option value="'.$key.'">'.$value['title'].'</option>'; echo '<option value="'.$key.'">'.$value['pris'].'</option>'; Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted May 20, 2014 Share Posted May 20, 2014 Just in case it was missed, did you see my reply? Does your real code have a query? As the code stands, $result is undefined. Have you tried turning on all PHP errors? To do that, you could add the following to your PHP script: <?php //REPORT ALL PHP ERRORS error_reporting(E_ALL); ini_set('display_errors', 1); ?> Quote Link to comment Share on other sites More sharing options...
loxfear Posted May 20, 2014 Author Share Posted May 20, 2014 (edited) i did see ur reply <?php include 'sqlconnect.php'; $sql = mysqli_query($con,"SELECT * FROM aktiviteter"); $data = array(); while ($row = mysqli_fetch_assoc($sql)) { $data[$row['id']] = array( 'title' => $row['title'], 'pris' => $row['pris'], ); } ?> <select name="country"> <option value="">-----------------</option> <?php foreach($data as $key => $value): echo '<option value="'.$key.'">'.$value.'</option>'; //close your tags!! endforeach; ?> </select> atm it sees the array, and therefor there will be, array in the list, but what i need is the title of every row in there, its prob not that easy echo '<option value="'.$key.'">'.$value['title'].'</option>'; only shows one title ;/ Edited May 20, 2014 by loxfear Quote Link to comment Share on other sites More sharing options...
loxfear Posted May 20, 2014 Author Share Posted May 20, 2014 Nvm it suddently worked Quote Link to comment Share on other sites More sharing options...
loxfear Posted May 20, 2014 Author Share Posted May 20, 2014 now how do i make it echo the pris row beside the select ? 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.