Jump to content

Recommended Posts

hi all

 

I have "model" field in accessory category of product table which have values like "E71,E72,E73,E74......"

 

On the "mobile product" page i want to match the model of accessories with model of mobile and display them.

 

 


/* query to select all models from accessories category from product table */

$qry_model="select * from product_table where category_id=4";
$qry_model_result=mysql_query($qry_model);
while($qry_model_row=mysql_fetch_array($qry_model_result))
{
$desc_model_all = $qry_model_row['model'];
$desc_model_all = explode(',', $desc_model_all);

foreach ($desc_model_all as $value) 
{
echo $value; /* this outputs as E73E72 */
}
}

$mobile_model = $row['model'];

if($value == $mobile_model) /* problem starts here */
{

$qryc="select * from product_table where model = '$value' and category_id=4";

$resultc = mysql_query($qryc);
if(mysql_num_rows($resultc)>0)
{
// product detail is displayed here
}

Link to comment
https://forums.phpfreaks.com/topic/265344-display-accessory-according-to-model/
Share on other sites

I have "model" field in accessory category of product table which have values like "E71,E72,E73,E74......"

BZZZT! There's your problem. Don't store multiple values in one column because it'll only cause you headaches later.

Use a second table with (at least) two columns: one is for the product ID and the other is a "model". One product+model pair per row: if a product has three models then there will be three rows for it.

Since I don't know if there's a good MySQL solution, write a quick script that imports the data.

$results = mysql_query("SELECT id field, model FROM table");
while($row = mysql_fetch_array($results)) {
    if ($row['model']) {
        $query = "INSERT INTO new table (product id, model id) VALUES ({$row['id field']}, '" . implode("'), ({$row['id field']}, '", explode(',', $row['model'])) . "')";
        mysql_query($query);
    }
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.