Julian Posted June 17, 2009 Share Posted June 17, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/162577-loop-results-to-compare-data/ Share on other sites More sharing options...
RussellReal Posted June 17, 2009 Share Posted June 17, 2009 You're trying to CHECK the boxes that in the database, say they're checked? Quote Link to comment https://forums.phpfreaks.com/topic/162577-loop-results-to-compare-data/#findComment-858066 Share on other sites More sharing options...
Julian Posted June 17, 2009 Author Share Posted June 17, 2009 You're trying to CHECK the boxes that in the database, say they're checked? Yeap! Quote Link to comment https://forums.phpfreaks.com/topic/162577-loop-results-to-compare-data/#findComment-858069 Share on other sites More sharing options...
RussellReal Posted June 17, 2009 Share Posted June 17, 2009 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=''"; Quote Link to comment https://forums.phpfreaks.com/topic/162577-loop-results-to-compare-data/#findComment-858094 Share on other sites More sharing options...
Julian Posted June 17, 2009 Author Share Posted June 17, 2009 Thanks for the help. But it is not that simple. I'm comparing two tables, the common field is "id_especialidad". As I wrote, I almost achieved that but I need to loop in order to "check" the values. Quote Link to comment https://forums.phpfreaks.com/topic/162577-loop-results-to-compare-data/#findComment-858098 Share on other sites More sharing options...
Julian Posted June 17, 2009 Author Share Posted June 17, 2009 Help? anyone?... Quote Link to comment https://forums.phpfreaks.com/topic/162577-loop-results-to-compare-data/#findComment-858133 Share on other sites More sharing options...
RussellReal Posted June 17, 2009 Share Posted June 17, 2009 echo "<td width='18' valign='top'><input type='checkbox' id='espe' name='id_especialidad[]' ".(($row_espe['id_especialidad'] != $work['id_especialidad'])? 'checked="checked" ':'')."value=''"; Quote Link to comment https://forums.phpfreaks.com/topic/162577-loop-results-to-compare-data/#findComment-858382 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.