Forum Moderators: coopster

Message Too Old, No Replies

MySQL Result as Array

Insert Results in PEAR PAGER

         

5x54u

9:31 pm on Dec 6, 2005 (gmt 0)

10+ Year Member




$db= new MySQL($host,$dbUser,$dbPass,$dbName);
$sql=("SELECT * FROM sticker_files WHERE sticker_cat_id='8'");
$catdirs = $db->query($sql);
$dirs=$catdirs->fetch()

and I need a for each loop (i think)
to insert that data below:


$params = array(
'mode' => 'Jumping',
'perPage' => 3,
'delta' => 2,
'itemData' => array(****RESULTS HERE AS COMMA SEPARATED string)
);

Thank for help

I think it is a for each value of key as result or something

ergophobe

6:45 pm on Dec 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sorry, I don't understand the question. Instead of SELECT *, can you show the actual fields you're selecting? I'm not sure what's what in your sample data array.

Timotheos

9:30 pm on Dec 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From what I can tell you want to get your sql results into an array so you can insert it into $params['itemData']? But I'm not familiar with your syntax. What database extraction are you using? Does $catdirs->fetch() return an object or array?

ergophobe

10:41 pm on Dec 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I was going to add similar.

With standard mysql functions, you would just get an array

$result = mysql_query($sql);
$array = mysql_fetch_assoc($result);

In that case there's nothing to do. If you're in PHP5, you can also iterate through an object with a foreach and put it into an array that way.

Other than that, you can essentially transform an object into an array with

get_object_vars()

ergophobe

10:43 pm on Dec 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




What database extraction are you using?

I finally noticed - it's in the subtitle - PEAR

Anyway, depending on PHP version, one of the things I mentioned above should work, but I'm still not exactly certain what you're trying to put where.