Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , ,

Sponsored Links



Fill an array using a mysql database

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 16-04-2009
Jacek's Avatar
Member
 
Join Date: May 2008
Posts: 924
Fill an array using a mysql database

I'm trying to code a php page to generate a pdf. In this pdf I would like to have a table with products in: I have a request in the mysql database.
Code:
    1. $ commands_products = mysql_query ('SELECT * FROM WHERE lcg_shop_commands_products (id_command = 189)');
    2. $ data = mysql_fetch_array ($ commands_products)
I get a array.

and I would put it in another table
Code:
    1. $contentTable = array ($data ['name'], $data ['reference'], $data ['quantity'], $data ['price'], $data ['name'], $data ['reference'], $data ['quantity'], $data ['price'], etc. ...,);
As if I bum a listing of products with the id_command = 189.

but the problem is that I do not know how it finished. Have you any idea?
Reply With Quote
  #2  
Old 16-04-2009
switchblade327's Avatar
Member
 
Join Date: May 2008
Posts: 3,998
Re: Fill an array using a mysql database

You can do this:
Code:
$query = mysql_query($sql);
$contentTable = array();
while($contentTable[] = mysql_fetch_assoc($query)) ;
// View
foreach($contentTable as $row) {
foreach($row as $key => $value) {
echo "$key => $value<br />"
}
}
Reply With Quote
  #3  
Old 16-04-2009
Jacek's Avatar
Member
 
Join Date: May 2008
Posts: 924
Re: Fill an array using a mysql database

The code does not work, the display returns nothing, there was already one; on command echo.

I check my mysql command works fine.
Reply With Quote
  #4  
Old 16-04-2009
switchblade327's Avatar
Member
 
Join Date: May 2008
Posts: 3,998
Re: Fill an array using a mysql database

Put a print_r ($contentTable) after the while loop
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Fill an array using a mysql database"
Thread Thread Starter Forum Replies Last Post
PHP - I want to retrieve records from specific field from a MySQL table and build array using PHP bond007dev Software Development 3 19-07-2010 05:23 PM
How to fill an array with random number in c++? Juaquine Software Development 5 03-03-2010 05:34 PM
How to store byte array to database with JDBC? RogerFielden Software Development 3 23-09-2009 11:52 AM
How to Populate an Array for MYSQL FlayoFish Software Development 3 14-04-2009 01:28 PM
Auto fill word document from database kaotix MS Office Support 4 12-08-2008 07:38 AM


All times are GMT +5.5. The time now is 05:33 AM.