Jump to content

Recommended Posts

Hi guys.

 

I have almost everything done with this script.  What it does is show me checkboxes with text.  I achieved this with the following code:

<?php

//get the number of rows in our result so we can use it in a for loop
$numrows = (mysql_num_rows ($es));

// loop to create rows
if($numrows >0){
echo "<table width ='100%' border = '0' cellspacing = '5' cellpadding = '0'>";
// loop to create columns
$position = 1;
	while ($work = mysql_fetch_array($es)){
	  if($position == 1){echo "<tr>";}
	  echo "<td width='18' valign='top'><input type='checkbox' id='espe' name='id_especialidad[]' value=''";
	  if (!(strcmp($work['id_especialidad'],$row_espe['id_especialidad']))) {echo "checked";} //Loop here
	  echo "></td>";
	  echo "<td class='class10'>" . $work['especialidad'] . "</td> ";
	  if($position == 4){ echo "</tr> "; $position = 1;}else{ $position++;}
	}

$end = "";
 if($position != 1){
  for($z=(4-$position); $z>0 ; $z--){
  $end .= "<td></td>";
  }
  $end .= "</tr>";
 }
echo $end."</table> ";
}
						?>

 

I need to compare to tables to put "checked" where the user already checked the box. But I can show only the first record on the database checked.  I think I need to loop to compare buy don't know how.  Any help will be appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/162577-loop-results-to-compare-data/
Share on other sites

and the field in the database is 'checked'?

 

if so

 

do this:

 

  echo "<td width='18' valign='top'><input type='checkbox' id='espe' name='id_especialidad[]' ".(($work['checked'])? 'checked="checked" ':'')."value=''";

 

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.