Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am using this code to display multiple sql rows in a table. I want everytime i click the submit button on the right to run an sql query to update a value in the listings table where the user id is equal to the corresponding user id of each row. I am a bit confused on how to do it any help?

<?php
                       foreach($user_listings as $user_listing){
                               echo '<tr class="danger">';
                               echo '<td>'.$user_listing['user_id']. '</td>';
                               echo '<td>Pending Approval</td>';
                               echo '<td>'.  $user_listing['listing_header']. '</td>';
                               echo '<td>'.  $user_listing['listing_subheader']. '</td>';
                               echo '<td>'.  $user_listing['category']. '</td>';
                               echo '<td>'.  $user_listing['listing_city']. '</td>';
                               echo '<td>'.  $user_listing['listing_adress']. '</td>';
                               echo '<td>'.  $user_listing['listing_text']. '</td>';
                               echo '<td>';
                       ?>
                               <form action='' method='POST' class="approve-form">
                                   <input type='submit' value="Approve"  class="btn btn-success" name='submit' />
                                </form>
                   <?php       echo '</td>';
                               echo '</tr>';
                       }
                   ?>
                 </tbody>
Posted

1 solution

This solution may be quite tricky or lengthy even, sorry for that but it worked very well in a long run and was easy to debug to.

Step 1 maintain a hidden textbox
holding the row count of the table you create.
example $ count=count ($ user_listings);

step 2 process each value using for each

Step 3 inside for each on creating table create dynamic id for the textboxes
For ex <input id='<?php echo "listing_header".$iteratedvalue?>'></input>

On submit function

Process it the same way and fetch the values from the $post[dynamic ids]
Example
VB
<? php $ value =  $ POST ["listing_header". $ iteratedvalue '];?>
 
Share this answer
 
v4
Comments
Witchblade23 29-Mar-15 13:17pm    
Thank you for your answer, do you think i could also combine it with ajax so that the page dont refresh and jump up?
ramyajaya 29-Mar-15 16:51pm    
You can also combine with ajax if you need . as per the scenario which you have mentioned you might not need ajax if u want to store the entries made in front end
Witchblade23 29-Mar-15 17:51pm    
i am sorry but i tried the solution and i think i am missing something, could you collaborate a bit more in your steps above?
ramyajaya 29-Mar-15 18:19pm    
Could u pls check on to your errors or post your code
Witchblade23 29-Mar-15 18:37pm    
in step 3 what id do i have to give to the input field? Should i do the count outside the for each loop? I just can't understand how this will work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900