PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
webcan
Forum Commoner
Posts: 66 Joined: Tue Oct 28, 2003 2:25 pm
Location: Toronto, Canada
Post
by webcan » Wed Nov 26, 2003 5:21 pm
Hi there ...
I'm wondering how I can do this in PHP...
If I create an array such as this:
$dow[1] = "Monday";
$dow[2] = "Tuesday";
...
And I have a SQL database which contains the number 1 in another array, $row["id"], how can I get it to reference Monday?
I tried $dow[$row["name"]] but that doesn't work.
Thanks,
Peter.
infolock
DevNet Resident
Posts: 1708 Joined: Wed Sep 25, 2002 7:47 pm
Post
by infolock » Wed Nov 26, 2003 5:35 pm
$dow[1] = "Monday";
$dow[2] = "Tuesday";
And I have a SQL database which contains the number 1 in another array, $row["id"], how can I get it to reference Monday?
sorry, didn't quite follow what you are asking, but is this what you are trying to do ?
Code: Select all
<?php
if ($row["id"] = 1)
{
echo $dow[1];
}
?>
webcan
Forum Commoner
Posts: 66 Joined: Tue Oct 28, 2003 2:25 pm
Location: Toronto, Canada
Post
by webcan » Wed Nov 26, 2003 5:38 pm
No... it's more like:
Variables:
$dow[1] = "Monday";
$row["id"] = 1;
Long way:
$temp = $row["id"];
$this = $dow[$temp];
What's the short way?
mchaggis
Forum Contributor
Posts: 150 Joined: Mon Mar 24, 2003 10:31 am
Location: UK
Post
by mchaggis » Wed Nov 26, 2003 6:40 pm
simply:
Code: Select all
$this = $dowї$rowї"id"]];
webcan
Forum Commoner
Posts: 66 Joined: Tue Oct 28, 2003 2:25 pm
Location: Toronto, Canada
Post
by webcan » Wed Nov 26, 2003 6:45 pm
Well aren't I clever.
You were right... that is correct, and it's what I initially thought (first email), it was coming up blank because I forgot to declare $dow globally.
:-X
THANKS!