I just took over the webpage for my fraternity and am learning php. This is the code i have so far and it returns the people who are seniors. But it will not return any other category (junior, sophomore, etc.). I have some limited programming knowledge, but how do i get all these queries to execute??
you can see the results here,
http://www.indiana.edu/~delts/brothers.php
and you can see what the ultimate result should be here,
http://www.indiana.edu/~delts/brothers.php4
<?php
//connect to the database server
$db = mysql_connect();
mysql_select_db();
//report the connection failure or success
if (!$db) {
echo "there was a problem connecting to the database.";
exit;
}
if ($db) {
//run seniors query
$senior = mysql_query("SELECT name FROM brother WHERE year = 'senior' ORDER BY name");
if (!$senior) {
echo "An error occured at seniors.\n";
exit;
}
$senior_num_rows = mysql_num_rows($senior);
$senior_row = mysql_fetch_row($senior);
//display Seniors then members below
echo "<tr><td colspan=3 align=center><b>Seniors</b></td></tr>";
for ($i=0; $i <= ($senior_num_rows+1);) {
echo "<tr align=center>";
for ($t=0; $t < 3; $t++) {
echo "<td>";
$senior_row = mysql_fetch_array($senior, MYSQL_BOTH);
printf("%s", $senior_row["name"]);
echo "</td>";
}
echo "</tr>";
$i = $i+3;
}
$i=0;
//run Juniors query
$result = mysql_query("SELECT name FROM brother WHERE year = 'junior' ORDER BY name");
if (!$result) {
echo "An error occured at juniors.\n";
exit;
}
$num_rows = mysql_num_rows($result);
$row = mysql_fetch_row($result);
//display Juniors then members below
echo "<tr><td colspan=3 align=center><b>Juniors</b></td></tr>";
for ($i=0; $i <= ($num_rows+1);) {
echo "<tr align=center>";
for ($t=0; $t < 3; $t++) {
echo "<td>";
$roman = mysql_fetch_array($result, MYSQL_BOTH);
printf("%s", $roman["name"]);
echo "</td>";
}
echo "</tr>";
$i = $i+3;
}
$i=0;
//run Sophomore query
$result = mysql_query("SELECT name FROM brother WHERE year = 'sophomore' ORDER BY name");
if (!$result) {
echo "An error occured at sophomores.\n";
exit;
}
$num_rows = mysql_num_rows($result);
$row = mysql_fetch_row($result);
//display Sophomore then members below
echo "<tr><td colspan=3 align=center><b>Sophomore</b></td></tr>";
for ($i=0; $i <= ($num_rows+1);) {
echo "<tr align=center>";
for ($t=0; $t < 3; $t++) {
echo "<td>";
$roman = mysql_fetch_array($result, MYSQL_BOTH);
printf("%s", $roman["name"]);
echo "</td>";
}
echo "</tr>";
$i = $i+3;
}
$i=0;
//run Neophytes query
$result = mysql_query("SELECT name FROM brother WHERE year = 'neophyte' ORDER BY name");
if (!$result) {
echo "An error occured at neophytes.\n";
exit;
}
$num_rows = mysql_num_rows($result);
$row = mysql_fetch_row($result);
//display Neophytes then members below
echo "<tr><td colspan=3 align=center><b>Neophytes</b></td></tr>";
for ($i=0; $i <= ($num_rows+1);) {
echo "<tr align=center>";
for ($t=0; $t < 3; $t++) {
echo "<td>";
$roman = mysql_fetch_array($result, MYSQL_BOTH);
printf("%s", $roman["name"]);
echo "</td>";
}
echo "</tr>";
$i = $i+3;
}
$i=0;
//run Pledges query
$result = mysql_query("SELECT name FROM brother WHERE year = 'pledge' ORDER BY name");
if (!$result) {
echo "An error occured at pledges.\n";
exit;
}
$num_rows = mysql_num_rows($result);
$row = mysql_fetch_row($result);
//display Pledges then members below
echo "<tr><td colspan=3 align=center><b>Pledges</b></td></tr>";
for ($i=0; $i <= ($num_rows+1);) {
echo "<tr align=center>";
for ($t=0; $t < 3; $t++) {
echo "<td>";
$roman = mysql_fetch_array($result, MYSQL_BOTH);
printf("%s", $roman["name"]);
echo "</td>";
}
echo "</tr>";
$i = $i+3;
}
$i=0;
}
?>