[thelist] mySQL join query newb

Burhan Khalid thelist at meidomus.com
Sun Sep 5 04:20:06 CDT 2004


On Fri, 2004-09-03 at 13:56, ben morrison wrote:
> this is my first attempt at this, so ive been mangling some code.
> 
> im trying to write an XML file with all the categorys and photos.

You know that you can start MySQL with the -X flag to have it return
results as XML documents, right? :)

There are also various other classes available that can help you with
this. Try browsing PEAR [ http://pear.php.net ]

[ snipped out code ]

> out of interest is  foreach() similar to a for (i=0;i<value;i++) loop?

No, foreach is a special loop for collections. A for loop is for
iterating (doing any statement in preset intervals).

Although you can get similar effects with for() as you would with
foreach(), its recommended to use foreach() for collections (ie,
arrays).

For (pun) example:

$array = array("User" => "Jim", "Email" => "jim at company.com");

foreach($array as $users)
{ 
  echo $users;
}
foreach($array as $users => $email)
{ 
  echo "User ".$users." has ".$email;
}

(similar results using for)

$size = sizeof($array);
for ($i = 0; $i < $size; $i++)
{
  echo "User : ".$array["User"]." Email : ".$array["Email"];
}

And another example:

while(list($user,$email) = each($array))
{
  echo "User : ".$user." Email : ".$email;
}

Hopefully this helps.



More information about the thelist mailing list