eagleweb Posted October 4, 2007 Share Posted October 4, 2007 I presently have an include page with this code on it. On the calendar pages, it uses this info to color the dates on a calendar. [code] <?php $dayColor = 'e6e1d3'; $weekendColor = '666666'; $mincolor = '00CC66'; $maxcolor = 'cc0000'; ?> I want to pull this info from the database instead. This is what I have: <?php require_once('mysql_connect.php'); $calQuery = mysql_query ( "SELECT * FROM calendar", $mysql_connect); while ( $rowcal = mysql_fetch_array ( $calQuery ) ) { echo " ".$rowcal['code']." = ' ".$rowcal['info']." '<br>"; } ?> This gives me nice list of the items in the db - perfectly. But, it is an echo statement and it just echos the info on each of the pages instead of coloring the calendar dates. The db has the fields: id, code (which holds the $dayColor, etc), info (which holds the colors e6e1d3, etc) How do i get this to list all of the info without 'echoing' it so they are usable on the calendar pages as <?php echo $dayColor; ?> ? Thanks in advance![/code] Link to comment https://forums.phpfreaks.com/topic/71839-solved-while-statement/ Share on other sites More sharing options...
trq Posted October 4, 2007 Share Posted October 4, 2007 You need to format your output with html. Link to comment https://forums.phpfreaks.com/topic/71839-solved-while-statement/#findComment-361849 Share on other sites More sharing options...
MmmVomit Posted October 4, 2007 Share Posted October 4, 2007 I think you're looking for variable variable names. If I understood you correctly, the "code" column stores the name of the variable, and the "info" colums stores the value that should be stored in that variable. <?php require_once('mysql_connect.php'); $calQuery = mysql_query ( "SELECT * FROM calendar", $mysql_connect); while ( $rowcal = mysql_fetch_array ( $calQuery ) ) { $var_name = $rowcal['code']; $$var_name = $rowcal['info']; //echo " ".$rowcal['code']." = ' ".$rowcal['info']." '<br>"; } ?> That will do what you want, but I think you'd be better off with something like this. It helps organize your data. <?php require_once('mysql_connect.php'); $calQuery = mysql_query ( "SELECT * FROM calendar", $mysql_connect); $colors = Array(); while ( $rowcal = mysql_fetch_array ( $calQuery ) ) { $colors[$rowcal['code']] = $rowcal['info']; //echo " ".$rowcal['code']." = ' ".$rowcal['info']." '<br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/71839-solved-while-statement/#findComment-361852 Share on other sites More sharing options...
eagleweb Posted October 4, 2007 Author Share Posted October 4, 2007 Both ways work excellent! For some reason I could not make sense of how to do it. What you wrote makes perfect sense. Thank you very much! Link to comment https://forums.phpfreaks.com/topic/71839-solved-while-statement/#findComment-361866 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.