A question ?!!!
Posted: Wed Apr 13, 2011 10:51 am
Hi
I'm new to PHP and I want to write a script to compare two products.
I have a table named mt_entry with 3 colomns named ID, Field_type and Field_content.

As you see in the picture above, I have two products with two different IDs and different specifications. The code I have provided looks like this:
The missing part that I can't deal with is querying :
SELECT field_content FROM mt_entry WHERE `id`=$phone1 AND `Field_type`='model'
SELECT field_content FROM mt_entry WHERE `id`=$phone1 AND `Field_type`='brand'
SELECT field_content FROM mt_entry WHERE `id`=$phone1 AND `Field_type`='OS'
SELECT field_content FROM mt_entry WHERE `id`=$phone1 AND `Field_type`='status'
The function that I want from the code is that when the Field_type = model, show the related Field_content .
But having lot's of queries makes code awful. Is there any way to deal with this code ?!
I'm really new to PHP, so I would appreciate your help.
Thanks in advance!
I'm new to PHP and I want to write a script to compare two products.
I have a table named mt_entry with 3 colomns named ID, Field_type and Field_content.

As you see in the picture above, I have two products with two different IDs and different specifications. The code I have provided looks like this:
Code: Select all
<?php
if ( isset ($_GET['submit']) )
{
$phone1 = mysql_real_escape_string($_GET['phone1']);
$phone2 = mysql_real_escape_string($_GET['phone2']);
$query1 = mysql_query ("SELECT field_content FROM mt_entry WHERE `id`=$phone1") or die(mysql_error());
$query2 = mysql_query ("SELECT field_content FROM mt_entry WHERE `id`=$phone2")or die(mysql_error());
$row1 = mysql_fetch_assoc($query1);
$row2 = mysql_fetch_assoc($query2);
}
?>The missing part that I can't deal with is querying :
SELECT field_content FROM mt_entry WHERE `id`=$phone1 AND `Field_type`='model'
SELECT field_content FROM mt_entry WHERE `id`=$phone1 AND `Field_type`='brand'
SELECT field_content FROM mt_entry WHERE `id`=$phone1 AND `Field_type`='OS'
SELECT field_content FROM mt_entry WHERE `id`=$phone1 AND `Field_type`='status'
The function that I want from the code is that when the Field_type = model, show the related Field_content .
But having lot's of queries makes code awful. Is there any way to deal with this code ?!
I'm really new to PHP, so I would appreciate your help.
Thanks in advance!