ryeman98 Posted July 2, 2007 Share Posted July 2, 2007 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>"; } Quote Link to comment Share on other sites More sharing options...
Salis Posted July 2, 2007 Share Posted July 2, 2007 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 Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 2, 2007 Share Posted July 2, 2007 $acara == "yes" ... that'll always fail. $acara is a query resource, not a variable. Check a tutorial on database retrieval, http://www.tizag.com/mysqlTutorial/mysqlfetcharray.php for example. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 2, 2007 Share Posted July 2, 2007 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; } Quote Link to comment 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.