Jump to content

This mysql query works, but it wont display in a table, can you spot my error?


Recommended Posts

Hi Freaks

 

I've been working on the below query and it does just what I need it to in myphpadmin, but for some reason when I try to display it in the table on my page all I get is headers and a blank outline with nothing in it.

 

It's bound to be something simple and obvious but I can't seem to spot it!

 

This first bit just creates the dropdown list for the user to select a membership number.

mysql_connect("localhost", "XXXXX", "XXXXX") or die(mysql_error());
mysql_select_db("XXXXX") or die(mysql_error());
$query="SELECT MembershipNo FROM Player ORDER BY MembershipNo";
  
$result = mysql_query ($query); 
echo '<form action="" method="post">';
echo "<select name='MembershipNo'>";
// printing the list box select command
while($nt=mysql_fetch_array($result))
        {//Array or records stored in $nt
                echo "<option ";

                 if($_POST['MembershipNo'] == $nt[MembershipNo]) echo "selected=\"selected\"";

               echo " value=\"$nt[MembershipNo]\">$nt[MembershipNo]</option>";
                /* Option values are added by looping through the array */
        }
echo "</select>";// Closing of list box

 

 

Once they select a membership number from the first bit and hit 'Go' it should take the selected value and dump it into the below query, run the query and print the results in the table. It's this bit that doesn't work!!

 
?>
                  <input type="submit" value="Go" />
                  <a href="../print/VenuesLeaguePrintS3.php" target="_blank"><img src="../images/printicon.jpg" alt="Click for Printer Friendly  Page" width="31" height="31" align="absmiddle" id="Print" /></a><a href="print/<?php echo $_POST['MembershipNo'] ?>.php" target="_blank"></a></p>
          <h3><?php echo $_POST['MembershipNo'] ?> League Positions</h3>
<?php 
if (isset($_POST['MembershipNo']) && !empty($_POST['MembershipNo'])) {
//mySQL queries

$query = "SELECT Results.Date, Venue.VenueName, Results.VenueID, Venue.VenueID, Player.FirstName, Player.LastName, Results.Position, Position.Position, Position.Points
FROM Position, Player, Results, Venue
WHERE Player.MembershipNo = '".$_POST['MembershipNo']."'
AND Player.MembershipNo = Results.MembershipNo
AND Results.Position = Position.Position
AND Venue.VenueID = Results.VenueID
ORDER BY Results.Date DESC "; 
$result=mysql_query($query)
	or die ("couldn't execute query");


echo <<<html
<table border="1" width="480" cellpadding="1" cellspacing="1">
<tr><td align="center"><strong>Date</strong></td>
	<td align="center"><strong>Venue Name</strong></td>
	<td align="center"><strong>First Name</strong></td>
	<td align="center"><strong>Last Name</strong></td>
	<td align="center"><strong>Position</strong></td>
	<td align="center"><strong>Points</strong></td>
</tr>
html;

//Now start the loop.


$pos=1;


while($r = mysql_fetch_array($result)){
//and echo each new row

echo <<<html
<tr><td align="center">{$r['Results.Date']}</td>
	<td align="center">{$r['Venue.VenueName']}</td>
	<td align="center">{$r['Player.FirstName']}</td>
	<td align="center">{$r['Player.LastName']}</td>
	<td align="center">{$r['Results.Position']}</td>
	<td align="center">{$r['Position.Points']}</td>

</tr>
html;
$pos++;	}


//And close the table.
echo "</table>";
}
?>

 

Thanks in advance for the help :)

 

PHP_Idiot

The $r index names will be just the column portion that is being selected -

   <tr><td align="center">{$r['Date']}</td>
      <td align="center">{$r['VenueName']}</td>
      <td align="center">{$r['FirstName']}</td>
      <td align="center">{$r['LastName']}</td>
      <td align="center">{$r['Position']}</td>
      <td align="center">{$r['Points']}</td>

 

And as I have posted too many times, you should be learning php, developing php code, and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that php will help you. (Confirm the actual settings using a phpinfo() statement in case the php.ini that you are changing is not the one that php is using.) You will save a ton of time. In this case you would have gotten undefined index errors that would have alerted you that the index names you are using are not what the query is returning.

Hi PFM

 

Your absolutely right, I knew it would be something obvious..couldn't see for looking.

Also I consider my wrist slapped, and error reporting is now on - sorry I forgot it this time!

 

Thanks a lot for the help :-)

 

PHP_Idiot

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.