Stupid checkbox question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lakota
Forum Newbie
Posts: 2
Joined: Fri Apr 06, 2007 9:30 pm

Stupid checkbox question

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

How is $ProfessionOne set?
lakota
Forum Newbie
Posts: 2
Joined: Fri Apr 06, 2007 9:30 pm

Post 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]
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post 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.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

To set the default value of a checkbox to checked:

Code: Select all

<input type="checkbox" name="asdf" checked="checked" />
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

if ($row->value == "value") {
?>
<input type="checkbox" name="xxxx" checked="checked" />
<? } else { ?>
<input type="checkbox" name="xxxx" />
<? } ?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Follow califdon's suggestion to make sure that PHP is seeing what you think it is.
Post Reply