Page 1 of 1

Stupid checkbox question

Posted: Fri Apr 06, 2007 9:36 pm
by lakota
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


another checkbox question for the experts...

i have the following code:

Code: Select all

<?php
while($row = mysql_fetch_array($resultAllProfessionsOne))
  {
  echo "<input type=\"checkbox\" name=\"" . $row['ProfessionName'] . "\"  value=\"" . $row['ProfessionID'] . "\">";
  if ($row['ProfessionID'] == $ProfessionOne) { echo "Checked"; }
  echo $row['ProfessionName'];
  echo "<br />";
  } ?></td>
  <td>
  <?php
while($row = mysql_fetch_array($resultAllProfessionsTwo))
  {
  echo "<input type=\"checkbox\" name=\"" . $row['ProfessionName'] . "\"  value=\"" . $row['ProfessionID'] . "\">";
  echo $row['ProfessionName'];
  echo "<br />";
  } ?>
This pulls the options from the database, GREAT.

Now I can not for the life of me figure out how to get the checkbox "checked" from the value in the database? does the if statement above not cover that for the professionOne boxes?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Apr 06, 2007 10:13 pm
by feyd
How is $ProfessionOne set?

Posted: Fri Apr 06, 2007 10:27 pm
by lakota
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


ProfessionOne is set with a query in

Code: Select all

while($row = mysql_fetch_array($resultAllProfessionsOne))
here is part of the query:

Code: Select all

$qryGetProfessions =	"SELECT * FROM tblCharacterProfessions
									WHERE CharacterID = $CharacterID";
			if (!$resultGetProfessions = mysql_query($qryGetProfessions, $DBConnection)) {
				echo "DB Error, could not query the database\n";
				echo 'MySQL Error: ' . mysql_error();
				exit;
			}
			
			
			while ($row = mysql_fetch_assoc($resultGetProfessions)) {
				$intCount = $intCount + 1;
				if ($intCount == 1) {
					$ProfessionOne = $row['ProfessionID'];
				}
				if ($intCount == 2) {
					$ProfessionTwo = $row['ProfessionID'];
				}				
			}

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Apr 07, 2007 1:29 pm
by califdon
I suggest that you add some debugging code temporarily, to echo the value of $ProfessionOne and of the expression $row['ProfessionID'] just before the if statement. Then you will see why it's not adding the 'checked' when you want it to.

Posted: Sat Apr 07, 2007 2:11 pm
by aaronhall
To set the default value of a checkbox to checked:

Code: Select all

<input type="checkbox" name="asdf" checked="checked" />

Posted: Sat Apr 07, 2007 2:43 pm
by ol4pr0

Code: Select all

if ($row->value == "value") {
?>
<input type="checkbox" name="xxxx" checked="checked" />
<? } else { ?>
<input type="checkbox" name="xxxx" />
<? } ?>

Posted: Sun Apr 08, 2007 3:26 pm
by RobertGonzalez
Follow califdon's suggestion to make sure that PHP is seeing what you think it is.