Jump to content

If yes, checkbox is checked, if no, checkbox isn't... isn't working.


ryeman98

Recommended Posts

So I have this code that if one of the entries columns says 'yes' then the checkbox should be checked and if the column says 'no' then the checkbox should be unchecked. My code isn't working. Help please?

 

$acara = mysql_query("SELECT * FROM CustomisationClothes WHERE acara='acara'");
$aisha = mysql_query("SELECT * FROM CustomisationClothes WHERE aisha='aisha'");
$blumaroo = mysql_query("SELECT * FROM CustomisationClothes WHERE blumaroo='blumaroo'");
	if ($acara == "yes") {
			echo "<td align='center'>Acara<br /><input type='checkbox' name='acara' value='".$acara."' checked='checked' /></td>";
	} else {
		echo "<td align='center'>Acara<br /><input type='checkbox' name='acara' value='".$acara."' /></td>";
	}

	if ($aisha == "yes") {
		echo "<td align='center'>Aisha<br /><input type='checkbox' name='aisha' value='".$aisha."' checked='checked' /></td>";
	} else {
		echo "<td align='center'>Aisha<br /><input type='checkbox' name='aisha' value='".$aisha."' /></td>";
	}

Link to comment
Share on other sites

By the looks of it you're only executing a query. Have you included a mysql_fetch_array()?

 

Querying a column id only half of what needs to be done. You can try something like:

$acara_query = mysql_query("SELECT * FROM CustomisationClothes WHERE acara='acara'");
$acara_array = mysql_fetch_array($acara_query);

 

$acara_array = mysql_fetch_array($acara_qurty); will pull information from the row. I'm not sure what column hold the jalue of 'yes' so I'll just use checked as an example.

 

$acara_query = mysql_query("SELECT * FROM CustomisationClothes WHERE acara='acara'");
$acara_array = mysql_fetch_array($acara_query);

$aisha_query = mysql_query("SELECT * FROM CustomisationClothes WHERE aisha='aisha'");
$aisha_array = mysql_fetch_array($aisha_query);

$blumaroo = mysql_query("SELECT * FROM CustomisationClothes WHERE blumaroo='blumaroo'");
	if ($acara_array['checked'] == "yes") {
			echo "<td align='center'>Acara<br /><input type='checkbox' name='acara' value='".$acara."' checked='checked' /></td>";
	} else {
		echo "<td align='center'>Acara<br /><input type='checkbox' name='acara' value='".$acara."' /></td>";
	}

	if ($aisha_array['checked'] == "yes") {
		echo "<td align='center'>Aisha<br /><input type='checkbox' name='aisha' value='".$aisha."' checked='checked' /></td>";
	} else {
		echo "<td align='center'>Aisha<br /><input type='checkbox' name='aisha' value='".$aisha."' /></td>";
	}

 

Hope this helps

Link to comment
Share on other sites

Also, unless the table only contains one column, you're probably selecting too much ("SELECT *...").  If you only want a single yes/no column, then put only that column in the column list.

 

$acara = @mysql_result(mysql_query("SELECT yn_column FROM CustomisationClothes WHERE acara='acara'"),0);

if ($acara == 'yes') {
blah;
} else {
blah;
}

Link to comment
Share on other sites

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.