Jump to content

Week array help...


FloridaNutz

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.