www.webdeveloper.com
Results 1 to 4 of 4

Thread: How to show message only once in a loop?

  1. #1
    Join Date
    Jul 2012
    Posts
    23

    Question How to show message only once in a loop?

    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.
    Code:
    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 "<br> 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

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    724
    ???
    Just move it out of the loop then?

  3. #3
    Join Date
    Mar 2014
    Posts
    24
    With the help of echo we can display the message.

  4. #4
    Join Date
    Feb 2014
    Location
    Canada
    Posts
    155
    You've asked for 2 different things: showing it when the loop finished and showing on the last count. Since it's meant to indicate when a new row was successfully added, it would make sense to move the echo statement outside the foreach loop.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles