<?php
$sql = mysql_query("SELECT * FROM testimonial ORDER BY id DESC");
//This block grabs the whole list for viewing
while($row = mysql_fetch_array($sql)){
$id = $row['id'];
$name = $row['name'];
$comment = $row['comment'];
$visibility = $row['visibility'];
$date_added = strftime("%b %d, %Y", strtotime($row['date_added']));}
This section is for buttons if i press the button named update it should update the field named "visibility" to approved and if i press the button named update1 it should update the field named "visibility" to hide
if(isset($_POST['update']))
{
$a = addslashes(strip_tags($_POST['update']));
$selected = mysql_query("SELECT * FROM `testimonial` WHERE id = '$id'");
$info = mysql_fetch_assoc($selected);
$sql = mysql_query("UPDATE `testimonial` SET `visibility` = 'approved' WHERE id = '$id'");
}
if(isset($_POST['update1']))
{
$a = addslashes(strip_tags($_POST['update1']));
$selected = mysql_query("SELECT * FROM `testimonial` WHERE id = '$id'");
$info = mysql_fetch_assoc($selected);
$sql = mysql_query("UPDATE `testimonial` SET `visibility` = 'hide' WHERE name='$name'");
}
this line is for the header of the table where i started the loop
$sql = mysql_query("SELECT * FROM testimonial");
echo '<form onSubmit="return validateForm()" action="testimonials.php" enctype="multipart/form-data" method="post">
<div align="center">
<table width="1273" border="1" cellspacing="0" cellpadding="6">
<tr>
<th width="119" bgcolor="#333333" scope="col"><strong>ID</strong></th>
<th width="88" bgcolor="#333333" scope="col"><strong>User</strong></th>
<th width="629" bgcolor="#333333" scope="col"><div align="center"><strong>Content</strong></div></th>
<th width="107" bgcolor="#333333" scope="col"><strong>Status</strong></th>
<th width="111" bgcolor="#333333" scope="col"><strong>Date Added</strong></th>
<th width="111" bgcolor="#333333" scope="col"><strong>Action</strong></th>
<th width="111" bgcolor="#333333" scope="col"><strong>Action</strong></th>
</tr>';
while($row = mysql_fetch_array($sql)){
echo'<tr>';
echo'<th width="119" scope="col">'.$row['id'].'</th>';
echo'<th width="88" scope="col">'.$row['name'].'</th>';
echo'<th width="629" scope="col"><div align="center">'.$row['comment'].'</div></th>';
echo'<th width="107" scope="col">'.$row['visibility'].'</th>';
echo'<th width="111" scope="col">'.$row['date_added'].'</th>';
This condition is to update the table field name "visibility" to posted if the visibility is equal to approved and if the other button is pressed it should update the table field "visibility" to not posted
$activ= $row['visibility'];
if ($activ=='approved'){ $visibility="Posted";} if ($activ=='hide'){$visibility="Not Posted";}
echo '<th width="107" scope="col">'.$visibility.'</th>';
echo'<th width="111" scope="col"><button type="submit" name="update" class="button" value='.$row['id'].'>Post</button><button type="submit" name="update1" class="button" value='.$row['id'].'>Unpost</button></th>';
echo'</tr>';
}
?>
</table>
</div>
</form>
Aucun commentaire:
Enregistrer un commentaire