PHP Array name question
Posted: Mon Jul 21, 2003 2:18 am
This should be an easy question to answer. 
I understand how to use variable names in my array statements:
I just started using joins in my SQL statements. So now I am faced with a weird situation. Look at the next example:
Oh, and one other question while I am at it. When using record set arrays like above, do I always have to imbed them like:
Or is there a way to imbed them like normal strings (this won't work):
Hmmm, don't think I have tried this before. Maybe this is the trick:
I understand how to use variable names in my array statements:
Code: Select all
<?php
.
.
.
$query = mysql_query("SELECT Name FROM Users WHERE ID=1");
while($Record=mysql_fetch_array($query))
{
echo "Username: ".$Recordї"Name"]."<br>";
}
.
.
.
?>Code: Select all
<?php
.
.
.
$query = mysql_query("SELECT Users.Name, Games.Name FROM Users INNER JOIN Games ON (Users.GameID = Games.ID) WHERE Users.ID=1");
while($Record=mysql_fetch_array($query))
{
// Here is the question. $Recordї"Users.Name"] won't work.
// $Recordї"Name"] won't work because there are 2 of them in the record set.
// I could just use $Recordї0] and $Recordї1], but it's kind of sloppy and error prone if I change the SQL statement.
// How do I acces these by name with this kind of query?
}
.
.
.
?>Code: Select all
echo "This users name is ".$Recordї"Name"]."...";Code: Select all
echo "This users name is $Recordї"Name"]...";Code: Select all
echo "This users name is $Recordї'Name']...";