Re: Loops

From: Date: Tue, 14 Dec 2004 17:38:43 +0000
Subject: Re: Loops
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-204321@lists.php.net to get a copy of this message
Richard Davey wrote:
Hello Steve, Tuesday, December 14, 2004, 3:52:26 PM, you wrote: SM> I would like to loop the multiple variables rather than put all the SM> variables into a single variable with an array. I can not figure out how to SM> do this. I assume you have placed the MySQL query and checked the number of rows it has returned? You could just do: while ($row == mysql_fetch_assoc($result)) {
      $name = $row['name'];
      $desc = $row['description'];
      echo "$name <br />";
      echo "desc <br />";
} and you're not just doing
echo $row['name'].'<br />'; by itself because...? It makes your code longer without any real reason :S yes it works, but is it useful?
This is just one of many ways of performing the same task. You could use a for() loop based on mysql_num_rows, you could use fetch_array instead of assoc. If you are only extracting a couple of details then you could even use mysql_result($result, $record, 'name'). I would suggest you take a look in the PHP manual, there are many examples of this. Best regards, Richard Davey


« previous php.general (#204321) next »