Little Chunk of PHP code

Chris S

Retired
Messages
2,055
Reaction score
1
Points
38
Can you guess what this does. it was hard to write so i hope its hard to guess

PHP:
		      <?php
		      $array1 = array();
		      $query1 = mysql_query("SELECT * FROM `point_option`") or die(mysql_error());
		        while ($row1 = mysql_fetch_array($query1)){
		          echo "<td>".$row1['name']."</td>";
		          $array1[] = $row1['name'];
		        }
		        ?>
		    </tr>
		      <?php
		        $grade = $_GET['grade'];
		        $query = mysql_query("SELECT * FROM `points` WHERE `grade` = '$grade'") or die(mysql_error());
		        while ($row = mysql_fetch_array($query)){
		      ?>
			<tr>
		      <td><?php echo $row['name']; ?></td>
		      <td><?php echo $row['grade']; ?></td>
		      <?php
		      foreach($array1 as $fName => $fInfo){
		          echo '<td>'.$row[$fInfo].'</td>';
		        }
		      ?>
		    </tr>
		    <?php
		    }
		    ?>


btw: Alejandro is not allowed to answer
 
Last edited:

bigguy

Retired
Messages
10,984
Reaction score
10
Points
38
It looks like it gets a name and grade of a person and shows it on a page. Is that right. ???
 

Trixter

New Member
Messages
384
Reaction score
0
Points
0
PHP:
<?php
              $array1 = array();
              $query1 = mysql_query("SELECT * FROM `point_option`") or die(mysql_error());
                while ($row1 = mysql_fetch_array($query1)){
                  echo "<td>".$row1['name']."</td>";
                  $array1[] = $row1['name'];
                }
                ?>
            </tr>

Copys All Names In point_option Table To $array1

PHP:
<?php
                $grade = $_GET['grade'];
                $query = mysql_query("SELECT * FROM `points` WHERE `grade` = '$grade'") or die(mysql_error());
                while ($row = mysql_fetch_array($query)){
              ?>

Fetchs Certain Grades Defind By $grade Which looks to Be Pulled From A Form Field

PHP:
 <tr>
              <td><?php echo $row['name']; ?></td>
              <td><?php echo $row['grade']; ?></td>
              <?php
              foreach($array1 as $fName => $fInfo){
                  echo '<td>'.$row[$fInfo].'</td>';
                }
              ?>
            </tr>
            <?php
            }
            ?>

Displays Names, Grades And List Number After The Query Has Run.
Thats What I Think
 
Last edited:

Chris S

Retired
Messages
2,055
Reaction score
1
Points
38
you are getting close. it does grab the people from a grade. but what does the array have to do with anything. doesn't look like people have figured that one out

heres what it outputs.

I did a little modifying to the output of the function that creates the array, but nothing else changed

outputVLY8.gif
 
Last edited:

YamiKaitou

Member
Messages
636
Reaction score
0
Points
16
Not sure where $fName and $fInfo come from, but judging by your output, it gets their name, their grade, and whether they attended the meeting in that month.
 

Chris S

Retired
Messages
2,055
Reaction score
1
Points
38
its really hard to see and the tables aren't that clear

what it does it queries 1 table for field names, and then makes an array.

then it queries another table for the information. it uses the array because the fields will change and i as the coder will not know what will be happening 2 years from now. So then using that array that was made, which contain the field names, it echos the field with the name from the array.

it was hard to write because i had no idea how i was going to output the rows and get the different field names because they will change.
 

amr1991

New Member
Messages
396
Reaction score
0
Points
0
Looks like to me before you told is a reputation mod for some kind of forum system
 

Fedlerner

Former Adm & Team Manager
Community Support
Messages
12,934
Reaction score
6
Points
38
I'm sure Torch will know what's this for :p
 
Top