I have inherited a site written using PHP. I am new to this and have found that part of the code doesn't do what it is meant to. The code is meant to pull teams from the mysql database and order them by team name. However the only entries that are displayed are those belonging to the first team name no others display. Could someone tell me what is wrong with the code. The code before and after this works ok. Thanks in advance. if($eventtype=='Team') {?> <table class="dsR52" border="0" cellspacing="0" cellpadding="4"> <tr> <td class="text" width="200"> <div align="left">Name</div> </td> <td class="text dsR28">Team</td> <td class="text dsR51">School</td> </tr> </table> <?php include ('../config/connector.php'); $query="SELECT * from entries where eventcode='$eventcode' and school='$schoolname' group by 'eventteam'"; $query_result = mysql_query ($query); $num_records = @mysql_num_rows ($query_result); $result = @mysql_query ($query); if ($num_records > 0) { while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $subeventteam=$row[5]; $subeventcode=$row[1]; ?><?php include ('../config.php'); $querylist="SELECT * from entries where eventcode='$subeventcode' and eventteam='$subeventteam'"; $resultlist = @mysql_query ($querylist); $num_recordlist = @mysql_num_rows ($resultlist); while ($row3 = mysql_fetch_array($resultlist, MYSQL_NUM)) { $studentname=$row3[8]; $eventteam=$row3[5]; $school=$row3[6]; ?> <table class="dsR49" border="0" cellspacing="0" cellpadding="4"> <tr> <td class="text" width="200"><?php echo $studentname;?></td> <td class="text"><?php echo $eventteam;?> <?php if ($num_recordlist>$max) { echo "<font color='red'>(".$num_recordlist.")</font>"; } elseif ($num_recordlist<$min) { echo "<font color='red'>(".$num_recordlist.")</font>"; } else { echo "<font color='green'> (".$num_recordlist.")</font>"; } ?> </td> <td class="text dsR51"><?php echo $school; ?></td> </tr> </table> <?php } echo '<hr noshade="noshade" size="1" width="100%" />';?><?php }}else{?> <p></p> <table width="100%" border="0" cellspacing="0" cellpadding="4"> <tr> <td class="text"><?php echo 'There are NO entries for event '.$eventcode;?></td> </tr> </table> <?php }?><?php}else Code (text):
One way to figure out what's wrong is to extract the query string SELECT * from entries where eventcode='$subeventcode' and eventteam='$subeventteam' and to run it to phpMyAdmin. (you'll have to replace the actual values of $subeventcode and $subeventteam. Try running select * from entries and see what results you get. Then add only one where condition SELECT * from entries where eventcode='$subeventcode' and see the effect.
if you want to list all of the records from database . don't use the where clause just use select * from tablename;
From the code, it looks like its grouping events together, so I'm guessing that the fields (eventcode, eventteam and school) are not unique identifiers, so its perfectly fine to have them in the WHERE clause