Results 1 to 4 of 4

Thread: Fill an array using a mysql database

  1. #1
    Join Date
    May 2008
    Posts
    923

    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?

  2. #2
    Join Date
    May 2008
    Posts
    3,971

    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 />"
    }
    }

  3. #3
    Join Date
    May 2008
    Posts
    923

    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.

  4. #4
    Join Date
    May 2008
    Posts
    3,971

    Re: Fill an array using a mysql database

    Put a print_r ($contentTable) after the while loop

Similar Threads

  1. Replies: 3
    Last Post: 19-07-2010, 04:23 PM
  2. How to fill an array with random number in c++?
    By Juaquine in forum Software Development
    Replies: 5
    Last Post: 03-03-2010, 05:34 PM
  3. File byte array to save in database
    By New ID in forum Software Development
    Replies: 5
    Last Post: 21-01-2010, 11:22 AM
  4. How to Populate an Array for MYSQL
    By FlayoFish in forum Software Development
    Replies: 3
    Last Post: 14-04-2009, 12:28 PM
  5. Auto fill word document from database
    By kaotix in forum MS Office Support
    Replies: 2
    Last Post: 08-08-2008, 06:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,626,932.81361 seconds with 17 queries