mrjameer Posted January 4, 2007 Share Posted January 4, 2007 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.thanksmrjameer Quote Link to comment https://forums.phpfreaks.com/topic/32854-publishunpublish-a-record-using-php/ Share on other sites More sharing options...
ober Posted January 4, 2007 Share Posted January 4, 2007 The answer to the question is Yes. Maybe you should ask the right question. Quote Link to comment https://forums.phpfreaks.com/topic/32854-publishunpublish-a-record-using-php/#findComment-152945 Share on other sites More sharing options...
mrjameer Posted January 7, 2007 Author Share Posted January 7, 2007 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.thanksmrjameer<?phpmysql_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><?phpwhile($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><?phpif($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> Quote Link to comment https://forums.phpfreaks.com/topic/32854-publishunpublish-a-record-using-php/#findComment-155085 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.