View Full Version : publish/unpublish a record using php
mrjameer
01-04-2007, 03:12 PM
hi,
i have a mysql table which contains some hosting plans info.there are 5 records inside the table.what i want to do is i want to put button like publish/unpublish for every record.so that whenever i dont want to publish a particular record i will simply click unpublish.is it posible to do this with php.any of your help will be greatly appreciated.
thanks
mrjameer
Linark
01-04-2007, 07:40 PM
Add a field to your hosting plans table called showPlan, then set it as ENUM 1,0.
Adjust your PHP to check this field first, if it is set to 1 then show plan, if it's 0 then do not show the field.
mrjameer
01-07-2007, 02:14 PM
hi,
i tried some code.the following code is used to display records from mysql table and dynamically creates a checkbox for every record.
when i click checkbox and press submit button,that particular record will be hided(unpublished),here the field 'published' value will be set to '0' means unpublished and '1' for published.upto this ok.
but what i want to do is when i want publish the same record again,how to code.if i create another button,how to make it in action.i want to code like this.
if published value='0' then if i click checkbox and press submit button,the published value='1'.if published value='1' then if i click checkbox and press submit button,the published value='0'.any of your help will be surely appreciated.
thanks
mrjameer
<?php
mysql_connect("localhost", "", "")or die("cannot connect");
mysql_select_db("mrj")or die("cannot select DB");
$sql="SELECT * FROM ahost";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<center><table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><font color="navy"><form name="form1" method="post" action=""><br><center><b>
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="lightgreen" align="center"><font color="navy">#</font></td>
<td bgcolor="lightgreen" align="center"><font color="navy"><strong>Id</strong></font></td>
<td bgcolor="lightgreen" align="center"><font color="navy"><strong>details</strong></font></td>
<td bgcolor="lightgreen" align="center"><font color="navy"><strong>bandwidth</strong></font></td>
<td bgcolor="lightgreen" align="center"><font color="navy"><strong>email_accounts</strong></font></td>
<td bgcolor="lightgreen" align="center"><font color="navy"><strong>published</strong></font></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<font color="navy">
<tr class="odd" onmouseover="over(this);" onmouseout="out(this);">
<td align="center"><font color="navy"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></font></td>
<td><font color="navy"><? echo $rows['id']; ?></font></td>
<td><font color="navy"><? echo $rows['details']; ?></font></td>
<td><font color="navy"><? echo $rows['bandwidth']; ?></font></td>
<td><font color="navy"><? echo $rows['email_accounts']; ?></font></td>
<td><font color="navy"><? echo $rows['published']; ?></font></td>
</tr></font>
<?php
}
?>
<tr>
<td colspan="5" align="center" ><input name="delete" type="submit" id="delete" value="unpublish">
</font></td>
</tr></table></center>
<?php
if($delete)
{
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "UPDATE ahost SET published='0' WHERE id='$del_id'";
$result = mysql_query($sql);
}
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=viewfiles1.php\">";
}
}
mysql_close();
?>
</table>
</form>
</font></td>
</tr>
</table></center>
pradip
12-02-2011, 02:34 PM
try this link http://ewizard.co.cc/blog/how-to-add-publish-unpublish-feature-using-Ajax-PHP-MySQL which shows how to add publish/unpublish feature to your content of the website using ajax, php and mysql. A perfect solution for your query
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.