Re: Loops

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Lynch wrote:
Steve Marquez wrote:

Greetings. I am trying to display looped information from a MySQL database
in a PHP file.

Loop

$name (witht a br />) then
$description

End of loop

I would like to loop the multiple variables rather than put all the
variables into a single variable with an array. I can not figure out how
to
do this.

I have very little knowledge of PHP but am learning. Let me know if more
information is needed.


//Untested code.
$connection = @mysql_connect('localhost', 'USERNAME', 'PASSWORD') or
trigger_error(@mysql_error() . " connecting to mysql", E_USER_ERROR);
mysql_error() *never* returns warnings... so why are you prepending an @ ?
@mysql_select_db('DATABASENAME', $connection) or
neither does mysql_select_db()
trigger_error(@mysql_error($connection) . " selecting database",
E_USER_ERROR);
$query = "select name, description from whatever order by name";
$people = @mysql_query($query, $connection) or
nor does mysql_query()
trigger_error(@mysql_error($connection) . " $query", E_USER_ERROR);
while (list($name, $description) = @mysql_fetch_row($people)){
nor does mysql_fetch_row, unless $people is not a mysql-resource, (thus being false,) which you already checked for.
  echo "<P>$name<BR>\n$description</P>\n";
}


Not to be rude, but adding so many @s is usually considered bad practice, and makes debugging scripts a hell of a lot harder.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux