Get specific results

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Get specific results

Post by GeXus »

I am trying to get a set of results seperated by their order of being returned.... for example, if i am returning 10 rows always, i would like to assign different variables to the selected columns for that row.. such as $row1[1] - $row1[2].. then $row2[1].. $row2[2].. What im basically doing is selecting top 10, and scattering the results in different areas of the site..

Any ideas on the best ways to do this?

Hope this makes sense.. heh..

Thanks!
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Code: Select all

$q = 'SELECT * FROM table ORDER BY id DESC LIMIT 10';
$result = mysql_query($q);
if ($result) {
    for ($i=0, $row = mysql_fetch_assoc($result); $i++) {
        $store[$i] = $row;
    }
} else echo 'Bad query';
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

ole wrote:

Code: Select all

$q = 'SELECT * FROM table ORDER BY id DESC LIMIT 10';
$result = mysql_query($q);
if ($result) {
    for ($i=0, $row = mysql_fetch_assoc($result); $i++) {
        $store[$i] = $row;
    }
} else echo 'Bad query';
Fantastic, thanks!
Post Reply