sarahAria Posted September 30, 2008 Share Posted September 30, 2008 I have the data for a class in below table (it's a class schedule and it draws the array on the week array) CREATE TABLE schedule( program TEXT NOT NULL, duration TEXT NOT NULL, day TEXT NOT NULL, clock TEXT NOT NULL ); & I need an array that should be like below (If I write below the array works) $classes_arr = array( // Classes for monday (day 1) $r[day] => array( $r[clock] => array( "html" => ".$r[program].", "style" => "background-color: #66CCCC", // use style property to change the background color "interval" => $r[duration] // set the interval for 2hrs ) ) ); now I need to put data from sql to the array ND PRODUCE AN ARRAY LIKE above one the final code should be like this ... $classes_arr = array(); while ($row=mysql_fetch_assoc($result)) { extract($row); $classes_arr = array( $day => array( 'clock' => '$clock', 'html' => '$program', 'style' => "background-color: #66CCCC", 'interval' => '$duration') ); } but it doesn't work any help? :'( thanks Sarah Quote Link to comment https://forums.phpfreaks.com/topic/126436-solved-inserting-from-sql-to-array/ Share on other sites More sharing options...
Jibberish Posted September 30, 2008 Share Posted September 30, 2008 Whats going wrong? are you getting an error? are no results coming back from the SQL query? etc. Quote Link to comment https://forums.phpfreaks.com/topic/126436-solved-inserting-from-sql-to-array/#findComment-653761 Share on other sites More sharing options...
Maq Posted September 30, 2008 Share Posted September 30, 2008 Try echoing your values out to make sure they're correct. Also put: ini_set ("display_errors", "1"); error_reporting(E_ALL); At the top of your page for temporary error display. Quote Link to comment https://forums.phpfreaks.com/topic/126436-solved-inserting-from-sql-to-array/#findComment-653776 Share on other sites More sharing options...
sarahAria Posted September 30, 2008 Author Share Posted September 30, 2008 the array seems to be empty! [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/126436-solved-inserting-from-sql-to-array/#findComment-654230 Share on other sites More sharing options...
sarahAria Posted September 30, 2008 Author Share Posted September 30, 2008 there seems to be an error with array cause even by replacing values with constants nothing changes?!!? unfortunately I don't know much about arrays :'( $classes_arr = array(); while ($row=mysql_fetch_assoc($result)) { extract($row); $classes_arr = array( 0 => array( 12 => array ( 'html' => '$program', 'style' => "background-color: #66CCCC", 'interval' => '120') )); Quote Link to comment https://forums.phpfreaks.com/topic/126436-solved-inserting-from-sql-to-array/#findComment-654246 Share on other sites More sharing options...
Barand Posted September 30, 2008 Share Posted September 30, 2008 don't put the variables inside single quotes $clock = '1230'; echo '$clock'; //--> $clock !!! echo $clock; //--> 1230 echo "$clock"; //--> 1230 Quote Link to comment https://forums.phpfreaks.com/topic/126436-solved-inserting-from-sql-to-array/#findComment-654298 Share on other sites More sharing options...
sarahAria Posted October 18, 2008 Author Share Posted October 18, 2008 thanks solved Quote Link to comment https://forums.phpfreaks.com/topic/126436-solved-inserting-from-sql-to-array/#findComment-668702 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.