Portal Home > Knowledgebase > Articles Database > Simple php array question please


Simple php array question please




Posted by lexington, 12-17-2008, 06:07 PM
Simple php array question please Hello, how can I insert the result of a query into an array so that it appears like the following quoted example if you print_r the info on a page? Quote: Array ( [0] => [1] => blah 1 [2] => blah 2 [3] => blah 3 [4] etc... There is a script that explodes one string into seperate parts and I am replacing that with separate database entries. I would like to insert each row into an array so I do not have to do such a serious rewrite of the script if all of the results are in an array already. I used: Quote: print_r(array($item_row['item_name'])); However it only displays one result and not all of the rows: Quote: Array ( [0] => blah 1 ) I know that it is possible since a year ago someone did this for me. Thanks! Last edited by lexington : 12-17-2008 at 05:11 PM.

Posted by lexington, 12-17-2008, 06:56 PM
If someone doesn't understand my question I can rephrase it. Please help since I cannot finish this script unless I have this one simple command. A guy took 5 seconds and gave it to me a year ago and I cannot remember how it was done.

Posted by Codebird, 12-17-2008, 07:13 PM
can we see a part of the code or something, cause I guess the whole idea is wrong __________________Hicham MallahWeb Developer

Posted by lexington, 12-17-2008, 07:17 PM
Ok I think I just figured it out from searching a million pages on Google. This works: PHP Code: while ( $item_row = mysql_fetch_array($item_res) ) { ÂÂ*ÂÂ*ÂÂ*$newarray[] = $item_row['item_name']; } print_r($newarray);

Posted by Codebird, 12-17-2008, 07:19 PM
cool, there was no use searching u said you want to put the rows into an array then u were trying to print_r a single row as an array __________________Hicham MallahWeb Developer

Posted by Anasule, 12-18-2008, 10:14 AM
Lexington you can use foreach. Code: foreach ($item_row as $name=> $value) { echo 'Name: '.$name.' - Value: '.$value.'
'; }

Posted by lexington, 12-18-2008, 10:15 AM
Thanks man but I got what I needed

Posted by bager, 12-18-2008, 11:39 AM
Try this http://adodb.sf.net

Posted by csparks, 12-20-2008, 11:09 PM
bager, what does a database abstraction layer have to do with the original question? __________________ Craig Sparks | Web Developerhttp://www.jexlabs.com

Posted by bager, 12-20-2008, 11:29 PM
Quote: Originally Posted by csparks bager, what does a database abstraction layer have to do with the original question? He can find or use what he needs with this library.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
SSH help (Views: 608)