1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with MySQL for an online shop.

Discussion in 'HTML, Graphics & Programming' started by vaultingSlinky, 21 Oct 2009.

  1. vaultingSlinky

    Mobster

    Joined: 2 Apr 2004

    Posts: 2,708

    Location: Aberdeen

    Basically I am very new to web development, and self taught so cut me some slack, but I need your help! I'm not using an existing ecommerce solution, as I wanted to build my own.

    The following code currently would give me a series of catalogue numbers from a database (mysql) containing information from paypals IPN service.

    Code:
    $result = mysql_query("SELECT * FROM ipndatabase WHERE payment_status='confirmed')
    
    while($row = mysql_fetch_array($result))
    {
    echo "<p>" . $row['item_number'] . "</p>;
    }
    
    It only selects the catalogue numbers where the payment has been confirmed.

    I want to build a page for the admin area showing items that are ready for dispatch and so I need to fetch information from my other table containing all the item information (pictures, description etc) based on the output from the code above.

    In the catalogue table the primary key is the number that would be outputted by the code shown above.

    I tried following the initial query with a second where i had defined the output from the above code as a variable, but I don't entirely understand arrays so I'm guessing this was an error (well it didn't work so I'm sure it's wrong :p)

    Code:
    $row['item_number']=$itemnumber
    mysql_query("SELECT * FROM catalog WHERE image_id='$itemnumber')
    
    I've read the mysql tutorial on table union and joins etc, but I couldn't quite work out how I can apply that into php and my requirement.

    Thanks for reading
     
  2. vaultingSlinky

    Mobster

    Joined: 2 Apr 2004

    Posts: 2,708

    Location: Aberdeen

    Edit: Scratch that, I worked it out myself. I'll be less lazy in future

    Code:
    $result = mysql_query("SELECT catalog.*,ipn.* FROM (catalog, ipn) WHERE catalog.image_id = ipn.item_number AND ipn.payment_status = 'Completed' ORDER BY catalog.image_id ASC");
    
    
    	while($row = mysql_fetch_array($result))
    	  {
    
     
    Last edited: 21 Oct 2009