|
Posted by Shawn Wilson on 11/30/05 06:44
"FYP" <fyp@fyp.com> wrote in message news:dmja2a$hjr$1@domitilla.aioe.org...
> Hello,
>
> I wish to fetch a number of records from mysql, but each time it returns
> only a row.
>
> Any suggestions pls?
>
> tia
>
This is how I pull multiple records from mySQL:
$query = " SELECT * FROM `msgsummary` WHERE `userid` = '$userid' ORDER BY
msgdate DESC";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach($line AS $_NAME => $_VALUE) { $$_NAME = $_VALUE; }
*** then do whatever you are going to do with that record ***
}
The foreach line there just eliminates you having to assign variables the
long way (i.e. $money = $line['money']; ) After the foreach line, all your
fields in that row will have associated variables assigned. If you have
three fields - money, time, and amount... then after the foreach line you
will have $money, $time, and $amount already assigned.
Hope that helps.
--
Shawn Wilson
Navigation:
[Reply to this message]
|