I have a query issue that doesn't let display the data

Discussion in 'PHP' started by co.ador, Feb 8, 2010.

  1. #1
    I have the following implicit join query with the join of two tables on product_id and p.colon it would look as below. Right now the way it is, a warning message is displaying

    
    
    $query1= "select p.id, p.name, p.image, p.colon_id, v.product_id,v.price,v.description,v.image from products p,product_varieties v where p.colon=" .(int) $_GET['menu'] ." AND p.id = v.product_id ";
    $result = mysql_query($query3, $connection);
    while ($row4 = mysql_fetch_array($result)) { // line 258
    html....
    }
    
    
    PHP:
    But as I said PHP is throwing the following WARNING and ít's not letting the data to query and display

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in 
    public_html/example2.php on line 258
    Code (markup):
    Help...[/QUOTE]
     
    co.ador, Feb 8, 2010 IP
  2. webfighter

    webfighter Peon

    Messages:
    208
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try running your query directly at mysql prompt and see the result whether you aer getting result or not
     
    webfighter, Feb 8, 2010 IP
  3. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    mysql prompt is on phpmyadmin?
     
    co.ador, Feb 8, 2010 IP
  4. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #4
    i think theres a problem with your variable parsing into int.. try removing the space between them.
     
    bartolay13, Feb 8, 2010 IP
  5. viron86

    viron86 Active Member

    Messages:
    426
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #5
    you can do one thing that is first check if your query is correct or not to this print the query like echo $result
    then paste this echoed part in sql console of phpmyadmin and chek if your query is right or not
     
    viron86, Feb 8, 2010 IP
  6. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    it was a extra field I had in the query, Thank you.


    I have encounter that it displays three times the row of the same product, Plus prices and varieties of one product is displaying it in different rows as well.

    What I am trying to aim is the price 20.30 to display in small tray of the first row, then 25.90 display in the medium tray of the first row, and 30.90 display on large tray of the first row. As of displaying as it is now.

    CREATE TABLE products (
    id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
    name VARCHAR(255)
    );
    
    CREATE TABLE product_varieties (
    product_id INT,
    variety VARCHAR(100),
    price DOUBLE,
    description TEXT,
    PRIMARY KEY (product_id, variety)
    );
    
    INSERT INTO products (id, name) VALUES (1, 'Cotél de camarone');
    INSERT INTO product_varieties (product_id, variety, price) VALUES (1, 'Small Tray',   2.9, );
    INSERT INTO product_varieties (product_id, variety, price) VALUES (1, 'Medium Tray', 6.9,);
    INSERT INTO product_varieties (product_id, variety, price) VALUES (1, 'Large Tray', 8.9, );
    
    Code (markup):
    This is the link
    http://www.nyhungry.com/example2.php?subject=4&id=2&register=1&menu=38

    What's your take on this.
     
    co.ador, Feb 9, 2010 IP
  7. blacksheep666

    blacksheep666 Active Member

    Messages:
    68
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #7
    
    "select p.id, p.name, p.image, p.colon_id,
    	v.product_id, v.price, v.description, v.image as var_image
    from
    	products p
    left join 
    	product_varieties v on v.product_id = p.id
    where
    	p.colon = ".$_GET['menu']
    
    
    
    Code (markup):
     
    blacksheep666, Feb 9, 2010 IP
  8. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thank you blacksheep.
     
    co.ador, Feb 9, 2010 IP