PHP SQL query results showing twice
Posted: Sun Apr 25, 2010 2:46 am
Hi, i am hoping someone can help me. My understanding of PHP is pretty basic and I am learning by doing. Here's what I've done:
I've set up a PHP query of a normal SQL database on my web site. This database is a database containing first name, surname, event and other fields for results times, places etc for our running club. I want users to be able to query that database by either entering their first name, surname or event (in a drop-down).
This is working ok at the moment however when I get the results back from a query I am getting one result once and every other result twice. However if the contestant has only ever entered one race only one result is returned.
There may be something really obvious missing here but not having done any basic course I wouldn't have a clue.
http://www.sydneyfrontrunners.org/event_with_html.php
For testing enter ronald in the first name and you will see there are 5 returned results made up of 2 results returned twice and 1 result "city 2 surf 2008" returned once.
So if anyone can assist that would be awesome and much appreciated.
I am also getting this error message on the site the first time the page is visited but it doesn't appear after refreshing or querying: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sydneyfr/public_html/event_with_html.php on line 229
Thanks
Michael
___________________________________________________________________________________________________________________________
Here's the code:
I've set up a PHP query of a normal SQL database on my web site. This database is a database containing first name, surname, event and other fields for results times, places etc for our running club. I want users to be able to query that database by either entering their first name, surname or event (in a drop-down).
This is working ok at the moment however when I get the results back from a query I am getting one result once and every other result twice. However if the contestant has only ever entered one race only one result is returned.
There may be something really obvious missing here but not having done any basic course I wouldn't have a clue.
http://www.sydneyfrontrunners.org/event_with_html.php
For testing enter ronald in the first name and you will see there are 5 returned results made up of 2 results returned twice and 1 result "city 2 surf 2008" returned once.
So if anyone can assist that would be awesome and much appreciated.
I am also getting this error message on the site the first time the page is visited but it doesn't appear after refreshing or querying: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sydneyfr/public_html/event_with_html.php on line 229
Thanks
Michael
___________________________________________________________________________________________________________________________
Here's the code:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SYDNEY FRONTRUNNERS RESULTS</title>
<style type="text/css">
<!--
.style3 {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
color: #FFF;
}
.style8 {font-family: Arial, Helvetica, sans-serif}
.style9 {
color: #FFFFFF;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}
.style10 {
color: #FFFFFF;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
}
.style12 {
font-family: Arial, Helvetica, sans-serif;
font-size: 36px;
font-weight: bold;
color: #FF0000;
}
.style13 {
color: #FFF
}
.style16 {
font-family: Arial, Helvetica, sans-serif;
font-size: 9pt;
color: #003366;
}
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}
.style17 {
color: #FFFFFF;
font-weight: bold;
}
body {
background-color: #C00;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<table width="1041" style="border-bottom: 3px solid grey; border-top: 3px solid grey; border-left: 3px solid grey; border-right: 3px solid grey;"align="center">
<tr>
<td colspan="4" bgcolor="#FFFFFF"><span class="style12"><img src="images/running.gif" width="80" height="85" /> results database </span></td>
</tr>
<tr>
<td height="56" colspan="4"><span class="style3"><span class="style13">NEW!</span> - This database is being designed to hold ALL race results for all years. You may search by First Name, Surname or by Event. Some duplicate issues are being resolved and all the result details are being added once they have been verified.</span></td>
</tr>
<tr>
<td width="271"></td>
</tr>
<tr bgcolor="#003399">
<td><span class="style10">First Name </span></td>
<td width="226"><span class="style10">Surname</span></td>
<td width="485" class="style9">Event</td>
</tr>
<?php
//Sets post information
if (isset($_POST['submit'])) {
$rowID = $_POST['id1'];
if (isset($_POST['submit'])) {
$rowID = $_POST['id2'];
if (isset($_POST['submit'])) {
$rowID = $_POST['id3'];
//connects to database
mysql_connect("localhost","","") or die(mysql_error());
mysql_select_db("") ;
//retrieve the data from the table
$query = "SELECT * FROM results WHERE first_name='$id1' OR surname='$id2' OR race_name='$id3' ORDER BY first_name";
$result = mysql_query($query) ;
list($first_name, $surname, $race_name) = mysql_fetch_array($result);
}
}
}
?>
<tr>
<td><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="id1">
<input type="submit" name="submit" value="go" />
</form></td>
<td><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="id2">
<input type="submit" name="submit" value="go" />
</form></td>
<td><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="id3">
<option name="">Select</option>
<option name="2009 Antarctic Marathon">2009 Antarctic Marathon</option>
<option name="2009 Canberra Challenge Olympic Distance Triathlon">2009 Canberra Challenge Olympic Distance Triathlon</option>
<option name="2009 Canberra Marathon">2009 Canberra Marathon</option>
<option name="2009 Challenge Series Olympic Distance Triathlon">2009 Challenge Series Olympic Distance Triathlon</option>
<option name="2009 City 2 Surf">2009 City 2 Surf</option>
<option name="2009 Mothers' Day Fun Run">2009 Mothers' Day Fun Run</option>
<option name="2009 SFR Mardi Gras Fun Run">2009 SFR Mardi Gras Fun Run</option>
<option name="2009 SMH Half Marathon">2009 SMH Half Marathon</option>
<option name="2009 Sri Chinmoy Series - Race 1">2009 Sri Chinmoy Series - Race 1</option>
<option name="2009 Sri Chinmoy Series 2">2009 Sri Chinmoy Series 2</option>
<option name="2009 Sutherland 2 Surf">2009 Sutherland 2 Surf</option>
<option name="2009 Sydney Marathon Clinic Half Marathon">2009 Sydney Marathon Clinic Half Marathon</option>
<option name="2009 Sydney Sprint Distance Triathlon Race 3">2009 Sydney Sprint Distance Triathlon Race 3</option>
<option name="2009 Sydney Sprint Triathlon Series Race 4 & NSW Championships">2009 Sydney Sprint Triathlon Series Race 4 & NSW Championships</option>
<option name="2008 5th Annual Bondi Barefoot Soft Sand Races">2008 5th Annual Bondi Barefoot Soft Sand Races</option>
<option name="2008 Adidas 10 mile Phoenix Park - Dublin">2008 Adidas 10 mile Phoenix Park - Dublin</option>
<option name="2008 Akuna Bay Adventure Race">2008 Akuna Bay Adventure Race</option>
<option name="2008 Around the Bay Run">2008 Around the Bay Run</option>
<option name="2008 Asia Pacific OUTgames">2008 Asia Pacific OUTgames</option>
<option name="2008 Australian Long Course Triathlon Championships">2008 Australian Long Course Triathlon Championships</option>
<option name="2008 Australian Sprint Distance Championships">2008 Australian Sprint Distance Championships</option>
<option name="2008 Bridge to Brisbane">2008 Bridge to Brisbane</option>
<option name="2008 Brighton Beachside Dash">2008 Brighton Beachside Dash</option>
<option name="2008 Brisbane to Noosa 165km Ride">2008 Brisbane to Noosa 165km Ride</option>
<option name="2008 Canberra Marathon">2008 Canberra Marathon</option>
<option name="2008 China Coast Half Marathon">2008 China Coast Half Marathon</option>
<option name="2008 City 2 Surf">2008 City 2 Surf</option>
<option name="2008 Corporate Games">2008 Corporate Games</option>
<option name="2008 Defence Forces Lake Albert Attack - Melbourne">2008 Defence Forces Lake Albert Attack - Melbourne</option>
<option name="2008 Enticer Spring Triathlon">2008 Enticer Spring Triathlon</option>
<option name="2008 Fat Ass Manly to Palm Beach">2008 Fat Ass Manly to Palm Beach</option>
<option name="2008 Forster Triathlon">2008 Forster Triathlon</option>
<option name="2008 Gold Coast Half Marathon">2008 Gold Coast Half Marathon</option>
<option name="2008 Gold Coast Marathon">2008 Gold Coast Marathon</option>
<option name="2008 Great Ocean Road">2008 Great Ocean Road</option>
<option name="2008 Hunter Valley Run Festival - Teams Marathon">2008 Hunter Valley Run Festival - Teams Marathon</option>
<option name="2008 ICT Sports Day Hong Kong">2008 ICT Sports Day Hong Kong</option>
<option name="2008 Maroubra Fun Run">2008 Maroubra Fun Run</option>
<option name="2008 Melbourne Half Marathon">2008 Melbourne Half Marathon</option>
<option name="2008 Melbourne OUTgames">2008 Melbourne OUTgames</option>
<option name="2008 Mother's Day Classic">2008 Mother's Day Classic</option>
<option name="2008 Mudgee Half Marathon">2008 Mudgee Half Marathon</option>
<option name="2008 Olympic distance World Championships Trial race - Adelaide">2008 Olympic distance World Championships Trial race - Adelaide</option>
<option name="2008 SFR Mardi Gras Fun Run">2008 SFR Mardi Gras Fun Run</option>
<option name="2008 SMH Half Marathon">2008 SMH Half Marathon</option>
<option name="2008 Sports Day OUT">2008 Sports Day OUT</option>
<option name="2008 Sri Chinmoy 4km Race">2008 Sri Chinmoy 4km Race</option>
<option name="2008 Sri Chinmoy 7km Race">2008 Sri Chinmoy 7km Race</option>
<option name="2008 Sri Chinmoy Series 1">2008 Sri Chinmoy Series 1</option>
<option name="2008 Sutherland 2 Surf">2008 Sutherland 2 Surf</option>
<option name="2008 Sydney Run Festival">2008 Sydney Run Festival</option>
<option name="2008 Sydney Sprint Triathlon Race 1 Kurnell">2008 Sydney Sprint Triathlon Race 1 Kurnell</option>
<option name="2008 Sydney Sprint Triathlon Race 2 Kurnell">2008 Sydney Sprint Triathlon Race 2 Kurnell</option>
<option name="2008 Sydney Sprint Triathlon Race 3 Kurnell">2008 Sydney Sprint Triathlon Race 3 Kurnell</option>
<option name="2008 Sydney Triathlon Series Race 4 Kurnell">2008 Sydney Sprint Triathlon Race 4 Kurnell</option>
<option name="2008 Woy Woy to Gosford Bay Run">2008 Woy Woy to Gosford Bay Run</option>
<option name="2007 Australian Triathlon Championships - Huskisson NSW">2007 Australian Triathlon Championships - Huskisson NSW</option>
<option name="2007 Blackmores Bridge Run">2007 Blackmores Bridge Run</option>
<option name="2007 Blackmores Half Marathon">2007 Blackmores Half Marathon</option>
<option name="2007 Canberra Ultramarathon">2007 Canberra Ultramarathon</option>
<option name="2007 City 2 Surf">2007 City 2 Surf</option>
<option name="2007 Cole Classic Manly Beach - Open Water Swim">2007 Cole Classic Manly Beach - Open Water Swim</option>
<option name="2007 Corporate Games - Parramatta">2007 Corporate Games - Parramatta</option>
<option name="2007 Cronulla Triathlon">2007 Cronulla Triathlon</option>
<option name="2007 Gold Coast Half Marathon">2007 Gold Coast Half Marathon</option>
<option name="2007 Gold Coast Marathon">2007 Gold Coast Marathon</option>
<option name="2007 Hawaii Half Ironman Race">2007 Hawaii Half Ironman Race</option>
<option name="2007 JP Morgan Corporate Run">2007 JP Morgan Corporate Run</option>
<option name="2007 Kurnell Triathlon">2007 Kurnell Triathlon</option>
<option name="2007 Maroubra Fun Run">2007 Maroubra Fun Run</option>
<option name="2007 Mini Mosmarathon">2007 Mini Mosmarathon</option>
<option name="2007 Mother's Day Fun Run">2007 Mother's Day Fun Run</option>
<option name="2007 NSW Club Triathlon Championship One Mile Beach Port Stephens">2007 NSW Club Triathlon Championship One Mile Beach Port Stephens</option>
<option name="2007 Port Macquarie Australian Ironman/woman">2007 Port Macquarie Australian Ironman/woman</option>
<option name="2007 Rogaine Run">2007 Rogaine Run</option>
<option name="2007 Short Distance Triathlon - Kurnell">2007 Short Distance Triathlon - Kurnell</option>
<option name="2007 Six Foot Track - Blue Mountains">2007 Six Foot Track - Blue Mountains</option>
<option name="2007 SMH Half Marathon">2007 SMH Half Marathon</option>
<option name="2007 Sports Day OUT - Man of the Mountain">2007 Sports Day OUT - Man of the Mountain</option>
<option name="2007 Sports Day OUT - Woman of Steel">2007 Sports Day OUT - Woman of Steel</option>
<option name="2007 State Masters Championship – Campbelltown">2007 State Masters Championship – Campbelltown</option>
<option name="2007 Sydney Striders Manly">2007 Sydney Striders Manly</option>
</select>
<input type="submit" name="submit" value="go" />
</form></td>
</tr>
<tr bgcolor="#003399">
<td colspan="4"><div align="left">
<table width="978" border="0">
<tr>
<td width="296"><span class="style9">EVENT</span></td>
<td width="38"><span class="style9">KMS</span></td>
<td width="87"><span class="style9">DATE</span></td>
<td width="107"><span class="style9">FIRST NAME </span></td>
<td width="100"><span class="style9">SURNAME</span></td>
<td width="42"><span class="style9">BIB</span></td>
<td width="68"><span class="style9">PLACE</span></td>
<td width="54"><span class="style9">TIME</span></td>
<td width="70"><span class="style9">NET</span></td>
<td width="74"><span class="style9">DIV</span></td>
</tr>
</table>
<span class="style9"> </span></div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="4"><span class="style16">
<?php
//Prints result on screen
print "<table border=0 cellpadding=3>";
while($info = mysql_fetch_array($result))
{
print "<tr>";
print "<td width=300px>".$info['race_name'] . "</td> ";
print "<td width=15px>".$info['kms'] . "</td> ";
print "<td width=90px>".$info['date'] . "</td> ";
print "<td width=100px>".$info['first_name'] . "</td> ";
print "<td width=100px>".$info['surname'] . "</td> ";
print "<td width=50px>".$info['bib_no'] . " </td>";
print "<td width=45px>".$info['gun_place'] . " </td>";
print "<td width=40px>".$info['gun_time'] . " </td>";
print "<td width=65px>".$info['net_time'] . " </td>";
print "<td width=60px>".$info['division'] . " </td></tr>";
}
print "</table>";
?>
</span></td>
</tr>
<tr bgcolor="#003399">
<td colspan="4"><div align="center" class="style10">
<p> </p>
</div></td>
</tr>
</table>
<p>
</body>
</html>