[thelist] String compare

Santilal Parbhu santilal at scorpioneng.co.nz
Sun Jan 20 13:39:56 CST 2008



I am trying to create a form and a receiving script to create a form that
has a "Grade" checkbox and if the box is checked the user can pick a
particular "Round" from a drop down menu.  Because there can be a number of
"grades" and each grade has a corresponding "round", I had to find a way to
link the two together.  I decided to do this by concatenating "grade" with
"round" . When the script is received, I read grade and round values from a
database, and then concatenate the grade to the round.  Then I do a string
compare to find a match.  This will then tell me which round is linked to
which grade.  Everything seems to work, except that the comparison always
fails.  I have printed to the browser to check for a match, and they look
the same.  I am using PHP4.0.4 on a Windows platform running Apache server
for testing.  The code is below.  Some of my code is probably unnecessary -
I have been playing around trying to locate where things were going wrong.
Any help would be appreciated.


Sending script

            print '<p>Subject: <input type="text" name="subject" size="100"
maxlength="100" /></p>';

            print "<p> Please select the draws required. </p>";


            $query = "SELECT DISTINCT grade FROM $compdraw ORDER BY grade
";// For results, it is appropriate to get data from $compdraws rather than

            $query2= "SELECT DISTINCT new_round_id FROM $compdraw ORDER BY
new_round_id ";          

             if (@mysql_query($query)) {

             r= mysql_query($query);

                while ($row = mysql_fetch_row($r)) {


                print '<table border="1px"><tr><td>';

                print "<p>$rrow";

                print '<input type="checkbox" name="requireddraws[]" ';


                print"</input></td><td>Round: ";

                print '<select name="roundid[]">';

                    if (@mysql_query($query2)) {

                    $r2= mysql_query($query2);

                         while ($row2 = mysql_fetch_row($r2)) {


                           print "<option value=$rrow.$rrow2>";



                      print "</td></tr></select>";


                      print "</table>";             




Receiving Script

            //Identify which draws are required.

            $query = "SELECT DISTINCT grade FROM $compdraw ORDER BY
grade";// For results, it is appropriate to get data from $compdraws rather
than $compgrades.

                 if (@mysql_query($query)) {

                 $r= mysql_query($query);

                        while ($row = mysql_fetch_row($r)) {


(in_array($grd,$HTTP_POST_VARS['requireddraws'])) {

                              $draws[] = $grd;//Fills $draws with all grades
requiring results.

                              $nl = 0; //Reset loop counter.

                              $rounds_count =
count($HTTP_POST_VARS['roundid']);//Fetches the number of grades requiring

                                    while ($nl < $rounds_count) {

                                     $query3 = "SELECT DISTINCT new_round_id
FROM $compdraw WHERE grade = '$grd' ORDER BY new_round_id";

                                          if (@mysql_query($query3)) {

                                          $r3= mysql_query($query3);

                                              while ($row3 =
mysql_fetch_row($r3)) {//Fetch all the rounds for each grade needing a

                                              $round_no = $row3[0];

                                              $round_identifier =

                                               $round_identity =

(trim($round_identity) == trim($grd.$round_no)) {

                                                    print "OK";         

                                                    $last_round_played[] =
$round_no ;




                                     $nl = $nl+1;











More information about the thelist mailing list