list records from mysql database

Discussion in 'PHP' started by benniss, Aug 28, 2008.

  1. #1
    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):
     
    benniss, Aug 28, 2008 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    learn how to query in mysql and you will find your answer yourself
     
    bartolay13, Aug 28, 2008 IP
  3. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #3
    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.
     
    ForumJoiner, Aug 29, 2008 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ...very helpful:rolleyes:
     
    JAY6390, Aug 29, 2008 IP
  5. justinlorder

    justinlorder Peon

    Messages:
    4,160
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #5
    if you want to list all of the records from database . don't use the where clause
    just use

    select * from tablename;
     
    justinlorder, Aug 29, 2008 IP
  6. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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
     
    JAY6390, Aug 30, 2008 IP