Jump to content

Archived

This topic is now archived and is closed to further replies.

FloridaNutz

Week array help...

Recommended Posts

Ok, i'm designing a website that has a sql datebase like this

(as Saved in SQL)
monMaleAge = Teen
monFemaleAge = Teen
tueMaleAge = 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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Again ... how the days are in relationship with the code of the if construct?
Sorry, but I really do not understand ...  :-\

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
$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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.