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>";
	}

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

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;
}

Archived

This topic is now archived and is closed to further replies.

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