rooney Posted September 27, 2007 Share Posted September 27, 2007 Hello friends I need some help regarding a site i am making. I need to finish it really very urgently but seem to be stuck at this point. The problem is that I am displaying all the rows of my table which have the value of the field 'approval' as 0. Now, there are to be 2 buttons next to each row with names "Approve" and "Disapprove". If you click on approve, then the value of 'approval' for that row becomes 1 and if you click on "Disapprove" , the value of 'approval' becomes -1. How to accomplish it ? as the list being viewed will be changing very often. I used this for loop for displaying the list and the corresponding boxes~ db_connect(); $query="SELECT * from info where approval=0"; $process=mysql_query($query); $num=mysql_num_rows($process); for($i = 0; $i< $num; $i++) { $row = mysql_fetch_assoc($process); $title[$i]=$row['title']; $url4[$i]=$row['url']; $widget[$i]=$row['widget']; $box[$i]=$row['box']; $button[$i]=$row['button']; $id[$i]=$row['id']; } echo "<table width=100% border='2' cellpadding='10' align='center'>"; echo " <th>title</th> <th>url</th> <th>widget</th> <th>box</th> <th>button</th>"; //displaying the list for($i = 0; $i< $num; $i++) { echo "<tr>"; echo "<td>".$title[$i]."</td>"; echo "<td>".$url4[$i]."</td>"; echo "<td>".$widget[$i]."</td>"; echo "<td>".$box[$i]."</td>"; echo "<td>".$button[$i]."</td>"; echo "<td>"; //creating two buttons - Approve and Disapprove echo "<form name='approve' method='post' action='pending.php'>\n"; echo "<input type= 'Submit' name= 'approve' value='approve' "; echo"</td>"; echo "<td>"; echo "<form name='disapprove' method='post' action='pending.php'>\n"; echo "<input type= 'Submit' name= 'disapprove' value='Disapprove' "; echo"</td>"; echo "</tr>"; //Trying to perform the desired action but not working if(isset($_POST['approve'])) { $sql = "UPDATE table info SET approval=1 WHERE url='". $url[$i] ."' "; $result = mysql_query($sql); } if(isset($_POST['disapprove'])) { $sql = "UPDATE table info SET approval=-1 WHERE url='". $url[$i] ."' "; $result = mysql_query($sql); } } ------------------------------------------------------------- There is the normal end coding after this. So, can anyone please suggest a way for me to do this ? Its very very very urgent. Almost a question of life and death at the moment. I request you to get me through this. Thanks to you all, Rooney Quote Link to comment https://forums.phpfreaks.com/topic/70891-need-final-help-regarding-updating-lists-on-page/ Share on other sites More sharing options...
MadTechie Posted September 27, 2007 Share Posted September 27, 2007 If "its very very very urgent." then it should be in the freelance section.. maybe try this echo "<form name='approve' method='post' action='pending.php'>\n"; echo "<input type= 'Submit' name= 'approve' value='approve' "; echo "<input type= 'hidden' name= 'ID' value='{$id[$i]}' "; echo"</td>"; if(isset($_POST['approve'])) { $ID =(int)$_POST['ID']; $sql = "UPDATE table info SET approval=1 WHERE id=$ID "; $result = mysql_query($sql); } Then move the code below the //Trying to perform the desired action but not working above the code $query="SELECT * from info where approval=0"; Quote Link to comment https://forums.phpfreaks.com/topic/70891-need-final-help-regarding-updating-lists-on-page/#findComment-356354 Share on other sites More sharing options...
rooney Posted September 27, 2007 Author Share Posted September 27, 2007 What you suggested makes perfect sense. But still not working. I think we might need separate names for all the buttons. like name="approve_".$id[$i] I am trying to figure out something. Quote Link to comment https://forums.phpfreaks.com/topic/70891-need-final-help-regarding-updating-lists-on-page/#findComment-356395 Share on other sites More sharing options...
MadTechie Posted September 27, 2007 Share Posted September 27, 2007 Na, your just missing the closing form tags ie echo "<form name='approve' method='post' action='pending.php'>\n"; echo "<input type= 'Submit' name= 'approve' value='approve' "; echo "<input type= 'hidden' name= 'ID' value='{$id[$i]}' "; echo"</form>"; echo"</td>"; Quote Link to comment https://forums.phpfreaks.com/topic/70891-need-final-help-regarding-updating-lists-on-page/#findComment-356396 Share on other sites More sharing options...
rooney Posted September 28, 2007 Author Share Posted September 28, 2007 $sql = "UPDATE table info SET approval=1 WHERE id=$ID "; had to be changed to $sql = "UPDATE table info SET approval='1' WHERE id=$ID "; Problem solved. Thanks a lot , Mad techie! Quote Link to comment https://forums.phpfreaks.com/topic/70891-need-final-help-regarding-updating-lists-on-page/#findComment-357010 Share on other sites More sharing options...
MadTechie Posted September 28, 2007 Share Posted September 28, 2007 Cool, can you please click solved (bottom left) Quote Link to comment https://forums.phpfreaks.com/topic/70891-need-final-help-regarding-updating-lists-on-page/#findComment-357139 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.