FloridaNutz Posted September 10, 2006 Share Posted September 10, 2006 Ok, i'm designing a website that has a sql datebase like this(as Saved in SQL)monMaleAge = TeenmonFemaleAge = TeentueMaleAge = 18+tueFemaleAge = 18+wedMaleAge = 21+wedFemaleAge = 21+...I also have corresponding images...MTeen.gif, M18.gif, M21.gif, FTeen.gif...How can I convert the "Teen" or "18+" to [code]<img src="images/Mteen.gif" width="21" height="18" /><img src="images/F18.gif" width="21" height="18" />[/code]*Edit*I think I need to do an array, but not really sure how...[code]$days = array(mon, tues, wed, thu, fri, sat, sun);[/code] Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 10, 2006 Share Posted September 10, 2006 What's this got to do with a weird day of the week problem?And can you explain the 'as Saved in SQL' which appears to be multiple variables only one of which can be true for each person. Quote Link to comment Share on other sites More sharing options...
°°Ben³ Posted September 10, 2006 Share Posted September 10, 2006 I do not understand how the data is in relationship with the code you posted. ??? Quote Link to comment Share on other sites More sharing options...
FloridaNutz Posted September 10, 2006 Author Share Posted September 10, 2006 Sorry, here's what i need to be done...[code]$days = array(mon, tues, wed, thu, fri, sat, sun);$possibleAges = array(18+, 21+, Teen);if ( $monMaleAge == "Teen" ) { $monMaleAge = '<img src="images/Mteen.gif" width="21" height="18" />'; } ; [/code]That's what it's supposed to do... but with everyday in the week and females too... Quote Link to comment Share on other sites More sharing options...
°°Ben³ Posted September 10, 2006 Share Posted September 10, 2006 Again ... how the days are in relationship with the code of the if construct?Sorry, but I really do not understand ... :-\ Quote Link to comment Share on other sites More sharing options...
FloridaNutz Posted September 11, 2006 Author Share Posted September 11, 2006 [code]example from sql would be $wenMaleAge = "18+" and $thurFemaleAge = "Teen"$daysMale = array("$monMaleAge", "$tueMaleAge", "$wedMaleAge", "$thuMaleAge", "$friMaleAge", "$satMaleAge", "$sunMaleAge"); $daysFemale = array("$monFemaleAge","$tueFemaleAge","$wedFemaleAge","$thuFemaleAge","$friFemaleAge","$satFemaleAge","$sunFemaleAge");$daysImage = array('<img src="images/Mteen.gif" width="21" height="18" />', '<img src="images/M18.gif" width="21" height="18" />', '<img src="images/F18.gif" width="21" height="18" />', '<img src="images/M21.gif" width="21" height="18" />', '<img src="images/F21.gif" width="21" height="18" />)');$ages = array("Teen", "18+", "21+");$agesCounter = 0;$daysCounter= 0;while ($agesCounter < 3) { while ($daysCounter < 7) { if ( $daysMale[$agesCounter] == $ages[$agesCounter] ) { $daysMaleImage[$daysCounter] = $daysImage[$daysCounter] ; }; if ( $daysFemale[$daysCounter] == $ages[$agesCounter] ) { $ageFemaleImage[$daysCounter] = $daysImage[$daysCounter] ; }; $daysCounter++; }; $agesCounter++; };}; [code]echo $ageMaleImage; $wenMaleAge = <img src="images/M18.gif" width="21" height="18" />echo $ageFemaleImage; $thurFemaleAge = <img src="images/FTeen.gif" width="21" height="18" />That's what I have got so far but... still doesn't work[/code][/code] Quote Link to comment Share on other sites More sharing options...
perezf Posted September 11, 2006 Share Posted September 11, 2006 $days = array(mon, tues, wed, thu, fri, sat, sun);change that to $days = array("mon", "tues", "wed", "thu", "fri", "sat", "sun");then $days[0] is mon$days[1] is tues$days[3] is wed$days[4] is thu and so on Quote Link to comment Share on other sites More sharing options...
jefkin Posted September 11, 2006 Share Posted September 11, 2006 If I understand your problem, then replaceing your quoted code with my sample should work for you.So, How about foreach? And, there's no need for the $daysMale and $daysFemale array (along with some other stuff)[code]// your database fetch, assuming you still build $monMaleAge, $tueMaleAge, etc...$days = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');$ages = array('Teen' => 'teen', '18+' => '18', '21+' => '21');foreach ($days as $day){ $varDB = "{$day}MaleAge"; $daysMaleImage[$day] = "<img src=\"images/M{$ages[$$var]}.gif\" width=\"21\" height=\"18\" />"; $varDB = "{$day}FemaleAge"; $daysFemaleImage[$day] = "<img src=\"images/F{$ages[$$var]}.gif\" width=\"21\" height=\"18\" />";}// to output your built arrays:echo "<table><tr><th>Day</th><th>Male</th><th>Female</th></tr>\n";foreach ($days as $day){ echo "<tr><td>$day</td><td>{$daysMaleImage[$day]}</td><td>{$daysFemaleImage[$day]}</td></tr>\n";}echo "</table>\n";[/code]If this doesn't do quite what you want, it should be close, though, I didn't actually test it.Jeff Quote Link to comment Share on other sites More sharing options...
FloridaNutz Posted September 12, 2006 Author Share Posted September 12, 2006 It didn't work... I don't quite understand how this for each command works... then again i'm dead tired too lol 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.