Jump to content

Need final help regarding updating lists on page


rooney

Recommended Posts

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

 

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";

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>";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.