Jump to content

Recommended Posts

Hey,

 

I have a database full of different articles/stories.

I would like to have a publish check box so that if it is checked, that story appears on the homepage, I know how to do this.

HOWEVER, i need ot be able to limit this so that only one can ever be checked off...

 

How would i do this?

Here is the code for my check box.

<tr class="tablelight">
	<td align="right" valign="top" class="editpdL"><strong>Publish?</strong></td>
	<td class="editpdR"><label>
	  <input name="publish" type="checkbox" id="publish" value="1" />
	</label></td>
</tr>

 

If there is already something in the "tips" table where "publish" = "1"

echo this:

<label>
	  <input name="publish" type="checkbox" id="publish" value="1" DISABLED/>
	</label>

 

 

 

I would recommend radio buttons. Only one is allowed to be selected at a time. If you want to keep the checkboxes and dynamically disallow them to be clicked, you would have to use javascript.

<input onclick="chkbox2.disabled=true; chkbox3.disabled=true" name="publish" type="checkbox" id="publish" value="1" />
<input onclick="publish.disabled=true; chkbox3.disabled=true" name="chkbox2" type="checkbox" id="chkbox2" value="2" />

 

every check box would need javascript like that for every box available, which doesn't make it very dynamically changable. If you use radio buttons, they are set up to do this automatically.

the problem is that the articles are not all on the same page... :( if u wish to publish the article u like "modify article" and it brings you to a page with all the article's content etc. There is a check box at the bottom where u would like whether u wan tit published or not.

Oh. It should be a simple check to see if an article is already on the front page. If there is always an article on the front page, it should be easy to remove that one before you set the new one, without even having to check for it. It might be easier to explain if I saw how you were implementing this.

here is the code on the "modify tip" page. this is where u select whether or not to publish the article, as well as change anything in the content.

<?

include 'admin_header.php';

// this part validates whether the user is logged in as a administrator or not
if($_SESSION['type'] != "admin")
{
echo "You are either not logged in, or logged in but with no authority to access this page.<br>please visit the log in page <a href=index.php>here</a>.";
}




else
{
// execute the real stuff if the login is valid

include 'admin_tipmenu.php';




?>

				<div align="center">

					<!-- end header -->
<?php
$sql = "SELECT * FROM tips WHERE id='".$_GET['idr']."'";
$sql = mysql_query($sql);
$product = mysql_fetch_array($sql);


if($_POST['title']!="")
{
// process the data load scheme


$update = "UPDATE tips SET  title='".$_POST['title']."', content='".$_POST['content']."', publish='".$_POST['publish']."' WHERE id='".$_GET['idr']."'";


echo $update."<br>";
mysql_query($update);

echo "<table align=\"center\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\" class=\"tableoutline\">
<tr>
<td class=\"success\">";
echo "Tip Was Updated Successfuly!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=admin_tips.php\"></td></tr></table>";



}// data load scheme ends here

else
{
?>
<br>
<form name="CreateProduct" method="post" enctype="multipart/form-data" action="<?php echo $_PHP_SELF; ?>">
						<br>
						<table border="0" width="100%" align="center">


	<tr>
		<td align="center">
		<?php
			if ($msg == "") {
				echo(" ");
			} else {
				echo($msg);
			}
		?>
		</td>
	</tr>
</table>
						<table align="center" border="0" cellpadding="0" cellspacing="0" class="tableoutline">
<tr>
<td>
<table align="center" border="0" cellpadding="10" cellspacing="0" bgcolor="#ffffff" style="border: 1px solid #000000">
<tr class="colorheader">
	<td align="center" colspan="2" class="colorhedr"><font class="section">Edit A Money Tip</font></td>
</tr>
<tr class="tabledark">
	<td align="right" class="editpdL"><strong>Title</strong></td>
	<td class="editpdR"><input type="text" name="title" class="inputbox" size="70" value="<?echo $product['title'];?>"></td>
</tr>


<tr class="tablelight">
	<td align="right" valign="top" class="editpdL"><strong>Content</strong></td>
	<td class="editpdR">
		<textarea name=content rows="60" cols="70"><?echo $product['content']?></textarea>		</td>
</tr>	

<tr class="tabledark">
	<td align="right" class="editpdL"><strong>Publish?</strong></td>
	<td class="editpdR"><input type="Checkbox" name="publish" value="1" <? if($product['publish']==1){echo "checked";}?>></td>
</tr>


    
<tr class="tabledark">
	<td class="editfootSingle" colspan="2" align="center">

		<input type="submit" name="Create" value="Modify Money Tip" language="javascript" onclick="return button_onclick(CreateProduct)" class="inputsubmit">		</td>
</tr>
</table>

</td>
</tr>	  
    </table>		

	</form>

					<br>
					<!-- begin footer --></div>
			<?
				 }
}


			include 'admin_footer.php';




			?>

 

 

This is just a concept idea, I'm not sure how your database works or if I even typed everything right, anyway, but take a look at this:

"UPDATE tips SET  title='".$_POST['title']."', content='".$_POST['content']."', publish = IF((SELECT COUNT(publish) FROM tips WHERE publish=1)>0,0,".$_POST['publish'].") WHERE id='".$_GET['idr']."'";

 

The idea is that you check if there are any values that currently have published set to 1. If there are, you don't set the new one. Of course, that just stops someone from setting a new one to published, but you can use the concept to do whatever you want. Make a query to see if any are published. If none are, set it to published. If at least one (Only one should be) is, then remove it, and then go on to set the new one to published. It would be something like this:

$qry = mysql_query("SELECT id, publish FROM tips WHERE publish=1");
$row = mysql_fetch_array($qry);
if ($row['publish'] == 1)
mysql_query("UPDATE tips SET publish=0 WHERE id=".$row['id']);
$update = "UPDATE tips SET  title='".$_POST['title']."', content='".$_POST['content']."', publish='".$_POST['publish']."' WHERE id='".$_GET['idr']."'";

 

I think there is a way to do it with one query, but I'm not sure on the syntax.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.