0

I have a one form and onclick i want to remove image id from array without page refresh and after submit form i will update it in the DB.

I am using following code for this but no any success.

PHP Code:-

$total = count($oldimage);
                    //print_r($oldimage);
                    for($i=0;$i<$total;$i++)
                    {
                        $fimgsql="select * from cc_tbl_img_vid_upload where id='$oldimage[$i]'";
                        $gimgname=mysqli_query($db,$fimgsql) or die('Error');
                        $rw=mysqli_fetch_assoc($gimgname);
                        ?><b id="rm<?=$i?>">Remove<?=$rw['upload_url']?></b><br/><br/>
                            <script>$( "#rm<?=$i?>" ).click(function() {
                                <?php unset($oldimage[$i]);?>
                                alert(<?php echo $oldimage[$i]; ?>);
                                $( "#rm<?=$i?>" ).hide();
                            });</script>
                        <?php
                    }
                        sort($oldimage);
                        $oldimage=implode(',',$oldimage);

2 Answers 2

0

Unfortunately you can't directly execute PHP (server-side) based on a JavaScript (client-side) event like you have in your code.

You need to handle your arrays in JavaScript. You can json_encode a PHP array and use the JSON array in your JavaScript, which is probably the closest you will get to doing what you're trying to do.

Sign up to request clarification or add additional context in comments.

2 Comments

Just tell me How i will use it in my scenario?
0

It's not possible the way you want to do it.PHP is serverside - which means you need to send a request to the server and get the response back(refreshing/changing page) while js is client side, and manipulates the UI, in order to achive that you must use AJAX (making a request from behind, and not seen by the user and getting the response, and based on it's output change the UI for the user)

Read this link - http://api.jquery.com/jquery.ajax/ ajax isn't that hard, but you must understand it, if you have php/mysql/html/css/js/jquery knowledge you will get it in no time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.