Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    publish/unpublish a record using php

    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

  • #2
    New Coder
    Join Date
    Nov 2006
    Location
    UK
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    - Mark

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #4
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile publish/unpublish record using php and ajax

    try this link http://ewizard.co.cc/blog/how-to-add...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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •