Jump to content


Photo

Week array help...


  • Please log in to reply
8 replies to this topic

#1 FloridaNutz

FloridaNutz
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 10 September 2006 - 09:46 PM

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

<img src="images/Mteen.gif" width="21" height="18" />
<img src="images/F18.gif" width="21" height="18" />

*Edit*
I think I need to do an array, but not really sure how...
$days = array(mon, tues, wed, thu, fri, sat, sun);


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 10 September 2006 - 09:52 PM

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.
Legend has it that reading the manual never killed anyone.
My site

#3 °°Ben³

°°Ben³
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationGermany / Remagen

Posted 10 September 2006 - 09:52 PM

I do not understand how the data is in relationship with the code you posted.  ???
desktop and web development ;)
---
English is not my native language. Please excuse if I made some errors in expression.

#4 FloridaNutz

FloridaNutz
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 10 September 2006 - 10:00 PM

Sorry, here's what i need to be done...

$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" />';					
	} ;		

That's what it's supposed to do... but with everyday in the week and females too...

#5 °°Ben³

°°Ben³
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationGermany / Remagen

Posted 10 September 2006 - 10:38 PM

Again ... how the days are in relationship with the code of the if construct?
Sorry, but I really do not understand ...  :-\
desktop and web development ;)
---
English is not my native language. Please excuse if I made some errors in expression.

#6 FloridaNutz

FloridaNutz
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 11 September 2006 - 02:36 AM


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]


#7 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 11 September 2006 - 03:32 AM

$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

#8 jefkin

jefkin
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 11 September 2006 - 04:24 AM

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)

// 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";

If this doesn't do quite what you want, it should be close, though, I didn't actually test it.

Jeff

#9 FloridaNutz

FloridaNutz
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 12 September 2006 - 04:25 AM

It didn't work... I don't quite understand how this for each command works... then again i'm dead tired too lol




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users