You are here: Re: how to fetch records from mysql? « PHP Language « IT news, forums, messages
Re: how to fetch records from mysql?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация