Welcome to WebmasterWorld Guest from 35.171.146.16

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

MySQL Result as Array

Insert Results in PEAR PAGER

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

Junior Member

10+ Year Member

joined:Oct 21, 2003
posts:158
votes: 0



$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

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

Senior Member

WebmasterWorld Senior Member ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8637
votes: 283


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.
9:30 pm on Dec 7, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 13, 2003
posts:775
votes: 0


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?
10:41 pm on Dec 7, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8637
votes: 283


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()

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

Senior Member

WebmasterWorld Senior Member ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8637
votes: 283



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.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members