Hi PhPeople!
I am having a problem with a conditional statement - and am hoping a fresh set of eyes can point this out to me... I'm sure it's something stupid I've missed!
I am populating a table with results from a simple query,
if there are results I want to print them to screen (no problems here!) and if there are no results I want to print a message ("No data found: please try again"
. The problem is I can't get the error message to display, even though I know I'm entering a query that wont return anything. Here's my code:
<snip>
$results = odbc_exec($connect,$query);
while (odbc_fetch_row($results)){
$lastname = odbc_result($results, 1);
$firstname = odbc_result($results, 2);
$address_line_1 = odbc_result($results, 3);
$address_line_2 = odbc_result($results, 4);
$city = odbc_result($results, 5);
$state_province = odbc_result($results, 6);
$zip_code = odbc_result($results, 7);
$phone_1 = odbc_result($results, 8);
if ($results){
print '<tr>
<td width="50%" align="left"><font face="Arial, Helvetica, Sans-serif" size="2">';
echo "<a href=\"#\" onClick=\"javascript
penListing('"
.$lastname."','"
.$firstname."','"
.$address_line_1."','"
.$address_line_2."','"
.$city."','"
.$state_province."','"
.$zip_code."','"
.$phone_1."')\">"
.$lastname."</a></font></td>";
print '<td width="50%" align="left"><font face="Arial, Helvetica, Sans-serif" size="2">'
.$firstname.'</font></td></tr>';
}
else{ //no results...
print '<font size="2" face="Arial, Helvetica, sans-serif">
<strong>No records found. Try again</strong></font>';
exit;
} //close if results
} //close while loop
print '</table></form>';
odbc_close($connect);//close the connection
} //close if (submitted)
</snip>
Any help at all would of course be greatly appreciated!
Cheers!
Laura
I am having a problem with a conditional statement - and am hoping a fresh set of eyes can point this out to me... I'm sure it's something stupid I've missed!
I am populating a table with results from a simple query,
if there are results I want to print them to screen (no problems here!) and if there are no results I want to print a message ("No data found: please try again"
<snip>
$results = odbc_exec($connect,$query);
while (odbc_fetch_row($results)){
$lastname = odbc_result($results, 1);
$firstname = odbc_result($results, 2);
$address_line_1 = odbc_result($results, 3);
$address_line_2 = odbc_result($results, 4);
$city = odbc_result($results, 5);
$state_province = odbc_result($results, 6);
$zip_code = odbc_result($results, 7);
$phone_1 = odbc_result($results, 8);
if ($results){
print '<tr>
<td width="50%" align="left"><font face="Arial, Helvetica, Sans-serif" size="2">';
echo "<a href=\"#\" onClick=\"javascript
.$lastname."','"
.$firstname."','"
.$address_line_1."','"
.$address_line_2."','"
.$city."','"
.$state_province."','"
.$zip_code."','"
.$phone_1."')\">"
.$lastname."</a></font></td>";
print '<td width="50%" align="left"><font face="Arial, Helvetica, Sans-serif" size="2">'
.$firstname.'</font></td></tr>';
}
else{ //no results...
print '<font size="2" face="Arial, Helvetica, sans-serif">
<strong>No records found. Try again</strong></font>';
exit;
} //close if results
} //close while loop
print '</table></form>';
odbc_close($connect);//close the connection
} //close if (submitted)
</snip>
Any help at all would of course be greatly appreciated!
![[cheers] [cheers] [cheers]](/data/assets/smilies/cheers.gif)
Laura