neilfurry Posted December 25, 2015 Share Posted December 25, 2015 Hello Mate, I have another problem, though i already fixed the problem on my previous post, i came across on another problem. i have this code: $sql = mysql_query("SELECT * FROM schedules") or die(mysql_error()); $results = array(); while($rs=mysql_fetch_array($sql)){ $results['events'] = array([ 'id' => (int)$rs['id'], 'start' => $rs['date_start'], 'end' => $rs['date_end'], 'title' => $rs['details'], 'free' => (bool)$rs['isfree'], 'userId' => (int)$rs['techID'], 'color' => render_color_code($rs['zip']) ]); } I have many events on my database, but only one is being displayed using the script above. how can i make it so that this script will get all events from my database. can you check what is wrong with my coding? Cheers! Neil Quote Link to comment https://forums.phpfreaks.com/topic/300002-help-on-returning-array-values/ Share on other sites More sharing options...
requinix Posted December 25, 2015 Share Posted December 25, 2015 You're overwriting $results['events'] every time. What you should do is start with "events" as an array and then add to it. $sql = mysql_query("SELECT * FROM schedules") or die(mysql_error()); $results = array('events' => array()); while($rs=mysql_fetch_array($sql)){ $results['events'][] = array( 'id' => (int)$rs['id'], 'start' => $rs['date_start'], 'end' => $rs['date_end'], 'title' => $rs['details'], 'free' => (bool)$rs['isfree'], 'userId' => (int)$rs['techID'], 'color' => render_color_code($rs['zip']) ); }And you're nesting your arrays wrong. array([]) will put an array inside another array. Use either the array() or [] syntax to get just the one array. Quote Link to comment https://forums.phpfreaks.com/topic/300002-help-on-returning-array-values/#findComment-1528589 Share on other sites More sharing options...
Solution neilfurry Posted December 25, 2015 Author Solution Share Posted December 25, 2015 Thanks mate, i just get it working... :-) cheers Neil Quote Link to comment https://forums.phpfreaks.com/topic/300002-help-on-returning-array-values/#findComment-1528591 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.