Very important case. I need your help now

Discussion in 'PHP' started by lenhhoxung, Jan 1, 2010.

  1. #1
    Dear Alls,

    I want to compare 2 products by PHP code with SQL. Is it the right code for me?

    here is my code

    $result1 = mysql_query("SELECT * FROM product WHERE product_sku=($fname)");// and (channel=($age)");
    $result2 = mysql_query("SELECT * FROM product WHERE product_sku=($fname2)");
    echo "<table border='1'>";

    while($row = mysql_fetch_array($result1))
    while($row = mysql_fetch_array($result2))
    {
    echo "<tr>";
    echo "<td></td>";
    echo "<td>Sản phẩm ". $_GET["fname"] ."</td>";
    echo "<td>Sản phẩm ". $_GET["fname2"] ."</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>Mã số KH</td>";
    echo "<td>" . $row['brand_id'] . "</td>";
    echo "<td>" . $row['brand_id'] . "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>kênh phân phối</td>";
    echo "<td>" . $row['product_sku'] . "</td>";
    echo "<td>" . $row['product_sku'] . "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>Tên tiệm</td>";
    echo "<td>" . $row['product_name'] . "</td>";
    echo "<td>" . $row['product_name'] . "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>Địa chỉ</td>";
    echo "<td>" . $row['product_desc'] . "</td>";
    echo "<td>" . $row['product_desc'] . "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>Quận</td>";
    echo "<td>" . $row['product_image'] . "</td>";
    echo "<td>" . $row['product_image'] . "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>Phone</td>";
    echo "<td>" . $row['product_price'] . "</td>";
    echo "<td>" . $row['product_price'] . "</td>";
    echo "</tr>";
    }

    echo "</table>";
    mysql_close($con);

    Thks for helping

    Sam
     
    lenhhoxung, Jan 1, 2010 IP
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #2
    You can select both products in one query like:
    $result = mysql_query("SELECT * FROM product WHERE product_sku=($fname) OR product_sku=($fname2)");
    PHP:
    after that:
    $product1 = mysql_fetch_array($result);
    $product2 = mysql_fetch_array($result);
     
    PHP:
    And then use these variables like:
    
    echo "<td>Tên tiệm</td>";
    echo "<td>" . $product1['product_name'] . "</td>";
    echo "<td>" . $product2['product_name'] . "</td>";
    echo "</tr>";
    
    PHP:
    and so on.
    I suppose that both of these products exist in database and each of $fname/$fname2 corresponds to on row in database;
     
    AsHinE, Jan 1, 2010 IP
  3. lenhhoxung

    lenhhoxung Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thks mate, but it does not work.
    Here is the code

    $result = mysql_query("SELECT SELECT * FROM product WHERE product_sku=($fname) OR product_sku=($fname2)");

    $product1 = mysql_fetch_array($result);
    $product2 = mysql_fetch_array($result);

    echo "<tr>"
    echo "<td>Tên tiệm</td>";
    echo "<td>" . $product1 . "</td>";
    echo "<td>" . $product2 . "</td>";
    echo "</tr>";
     
    lenhhoxung, Jan 1, 2010 IP
  4. lenhhoxung

    lenhhoxung Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This is the link http:// www. hs2lube . com /products/search.php?fname=1001&fname2=1008
     
    lenhhoxung, Jan 1, 2010 IP
  5. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #5
    Well, $product1 and $product2 - are arrays, so you need to echo them like $row in your example - $product1['product_desc'], $product1['product_name'] and so on.

    But as I can see there is a table with data on link you provided.
     
    AsHinE, Jan 1, 2010 IP