mySQL ignores first result

wxdqz

New Member
I've searched but my code is different to other replies. Simply, mySQL misses the first result but I don;t know why? Code Posted below:
##Commented problem area

Thanxinadvance
Pete Jones


<?
include("header.txt");

// Create mySQL connection
$connection = mysql_connect("localhost", "root", "") or die ("Couldn't connect to database");
$db = mysql_select_db("hwc", $connection) or die ("Couldn't select DB");

// Check something was selected
if (!$activityid || !$countryid):
print("No activity or country available to me! Click <a href=http://www.phpbuilder.com/board/archive/index.php/\"javascript:history.go(-1);\"> here </a> to return");
else:

// Create SQL query to get countyname and countyid for dropdown


$sql = "SELECT B.countryname, C.countyid, C.countyname FROM countries B, counties C WHERE C.countryid = B.countryid AND B.countryid = $countryid ORDER BY C.countyname";
$sql_result = mysql_query($sql,$connection);

// Create SQL query to count results
$sql = "SELECT O.locationid FROM countries B, counties C, districts D, owneractivitylocation O WHERE B.countryid = $countryid AND B.countryid = C.countryid AND C.countyid = D.countyid AND D.districtid = O.districtid AND O.activityid = $activityid";
$sql_countresult = mysql_query($sql,$connection);

$totalrows = mysql_num_rows($sql_countresult);
?>

<tr>

<td valign="top" colspan="25">
<table width=720 height="300" align="center" cellpadding="0" cellspacing="0">
<tr align="center">
<td valign="top" colspan="3">
<p><font size="3"><b><font color="#FF0000" size="4">Highway Code.com</font><font size="4">
Search Pages</font></b></font></p>
<h4>You are currently seaching in
<? $row = mysql_fetch_object($sql_result);
print($row->countryname);
?>
</h4>
</td>
</tr>
<tr>
<td valign="top" align="center" width="337" >
<p><font size="2">Click below to Show Entries in the <font color="#FF0000">HighwayCode.com</font>
database</font></p>
<p><a href="results.php3?activityid=<?print ($activityid)?>&countryid=<? print ($countryid) ?>"><img src="showentries.gif" width="120" height="50" border="0"></a></p>
<p><font size="2">Total number of locations available in
<?
print($row->countryname)
?> is
<?
print($totalrows)
?>
</font></p>
</td>
<td valign="top" align="center" width="46">
<p><img src="images/orsep.gif" width="45" height="120"></p>
</td>
<td valign="top" align="center" width="337"> <font size="2">Refine your
<font color="#FF0000">HighwayCode.com</font> Search by County </font>
<form name="counties" action="search3.php3" method="GET">
<p>
#################
##<select ##name=countyid>
## <?
##while($rows=mysql_fetch_object($sql_result)) {
## ?>
##<option value="<?print $rows->countyid ?>">
## <?
## print $rows->countyname?>
##</option>
## <?
## }
## ?>
##</select>
<input type="hidden" name="activityid" value="<? echo $activityid ?>">
<input type="hidden" name="countryname" value="<? print($row->countryname) ?>">
</p>
<p>
<input type="image" src="searchcounty.gif" name="submit" value="submit">
</p>
</form>
</table>
</td>
</tr>
<?
// Free Resources and Close Connection
mysql_free_result($sql_result);
mysql_close($connection);

include("footer.txt");
endif;
?>
 
Back
Top