SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Refering to array variables from mysql

    Hey all,

    Say I have a query such as the following:

    Code:
    SELECT orders.*, customers.* FROM orders, customers WHERE orders.id = customers.last_order
    If I execute this using PHP and then use the mysql_fetch_array() function with the intention of displaying the data, how are the array keys determined?

    I have tried:

    $row['orders.quantity'];
    $row['quantity'];

    and none of these seem to display anything. What should I be using?

    Thanks in advance

    -Sam
    Sam Hastings

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2002
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    try this

    You will be able to acces them by field name but perhaps you should name the fields in your query..

    Code:
    SELECT 
    orders.id AS order_id, 
    orders.quantity AS order_quantity, 
    orders.whatever AS order_whatever,
    customers.id AS customer_id, 
    customers.name AS customer_name, 
    customers.last_order AS customer_last_order
     
    FROM
    orders, customers 
     
    WHERE orders.id = customers.last_order
    
    Then you can access...

    $row['order_id];
    $row['customer_id];

    etc...

    Hope that helps

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good point, I hadn't thought of that!

    Thanks for the help

    -Sam
    Sam Hastings


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
  •