rajeshkr Posted March 22, 2014 Share Posted March 22, 2014 hi, I have a loop on my code, i know it will show message everytime that code will run but i want that the message only show on the final count. for ($i = 0; $i < $post_count; $i++) { $sql[] = "INSERT INTO pro_customer_album_price(customer_id, customer_name, customer_user_name, sl_no, album_name, paper, finish, price, vat, total_amt, date, time) VALUES ('$customer_id','$customer_name','$customer_user_name','".$sl_no[$i]."','".$album_name[$i]."','".$paper_used[$i]."','".$finishing[$i]."','".$price[$i]."','".$vat[$i]."','".$total_amt[$i]."','$date','$time')"; } foreach ($sql as $query) { $data = mysqli_query($con, $query); if(!$data) { echo " Error".mysqli_error($con); } else { echo "Inserted!"; /// this is the message coming everytime but i want this message only show when the loop complete or in last count. } } Thanks Quote Link to comment Share on other sites More sharing options...
kicken Posted March 22, 2014 Share Posted March 22, 2014 Set a flag variable to indicate if there were any errors or not. Then after your loop check that variable and output the message. $hasErrors=false; foreach ($sql as $query){ $data = mysqli_query($con, $query); if (!$data){ $hasErrors=true; } } if (!$hasErrors){ echo 'Inserted!'; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.