Jump to content

What is the logic to update three images of same ID?


tahakirmani

Recommended Posts

I am trying to update 3 images of same product_id. I have a different product_table and Product_images table. The product_images table has 5 fields; image_id, product_id, name, images, ord. I am trying to update images for any specific product_id. The problem I was facing before was that it set the same 'Image' for all of the three 'images', that why I add 'ord' filed and it solver that problem. Now I have a new problem. I am unable to understand where to write update image' query. If I write it inside for loop then it runs 'Update Query' 6 times and if I write it outside for loop then its unable to find out $ord[] variable. Kindly tell the way to resolve this problem. Given below is the part of code I am working on.

/*
* ------------------- IMAGE-QUERY Test 002 --------------------
*/
if (isset ( $_FILES ['files'] ) || ($_FILES ["files"] ["type"] == "image/jpeg"))
{
$i = 1;
/*
* ----------------------- Taking Current Order_id ------------------------
*/

// $order_sql= "select MAX(ord) from product_images";
$order_sql = "SELECT ord from product_images where product_id=$id";
$order_sql_run = mysql_query ( $order_sql );
echo mysql_error ();
for($i = 1; $i <= $order_fetch = mysql_fetch_array ( $order_sql_run ); $i ++)
// while ($order_fetch= mysql_fetch_array($order_sql_run))
{)
echo 'ID ' . $order_id [$i] = $order_fetch [(ord)];
}

/*
* ----------------------- Taking Current Order_id ------------------------
*/
foreach ( $_FILES ['files'] ['tmp_name'] as $key => $tmp_name ) {
// echo $tmp_name."<br>";
// echo 'number<br>';
echo $image_name = $_FILES ["files"] ["name"] [$key];
$random_name = rand () . $_FILES ["files"] ["name"] [$key];
$folder = "upload/products/" . $random_name;
move_uploaded_file ( $_FILES ["files"] ["tmp_name"] [$key], "upload/products/" . $random_name );
echo '<br>';
echo $sql = "update product_images set name= '$random_name',images= '$folder' where product_id=$id andord=$order_id[$i]";
if ($query_run = mysql_query ( $sql )) {

echo '<br>';
echo 'Done';
}
else {
echo mysql_error ();
}
// $i=$i+1;
}
}


/*-------------------
IMAGE-QUERY Test 002
--------------------*/
Link to comment
Share on other sites

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.