Click to See Complete Forum and Search --> : ODBC Fetch Problem
d.brandusa
10-25-2004, 01:23 PM
This might be a dumb question, how do I form the script to show:
City, State ZIP
<?php
while($myrow=odbc_fetch_array($result2)) {
echo('
<tr>
<td width="499" height="20"><font size="2" color="#FFFFFF"><b>Address:</b> <font size="2" color="#E4705F">'.$myrow['City'].'</font></td>
</tr>
');
}
?>
I don't know the formatting to display more than 1 fetch entry next to eachother like: '.$myrow['City'].', '.$myrow['State'].' '.$myrow['Zip'].'
I Use Microsoft SQL
96turnerri
10-25-2004, 03:01 PM
whilst i have never used ODBC before try
while(odbc_fetch_row($result)) {
$city = odbc_result($result, "City");
$zip = odbc_result($result, "Zip");
$state = odbc_result($result, "State");
echo('<tr><td width="499" height="20"><font size="2" color="#FFFFFF"><b>Address:</b> <font size="2" color="#E4705F">$city, $zip, $state</font></td></tr>');
}
Paul Jr
10-25-2004, 06:14 PM
Originally posted by d.brandusa
I don't know the formatting to display more than 1 fetch entry next to eachother like: '.$myrow['City'].', '.$myrow['State'].' '.$myrow['Zip'].'
What's wrong with doing it exactly like that? It looks fine to me.
d.brandusa
10-25-2004, 06:26 PM
It works now, I didn't realize one part of the code I had an extra ' symbol. I have another question, is there anyway to say if whatever field doesn't have an entra to post "N/A" instead of just blank?
Paul Jr
10-25-2004, 06:35 PM
What would be the value of the field if it wasn't filled out? NULL? Empty? Assuming it is empty, you could use the ternary operator like so:
echo('
<tr>
<td width="499" height="20"><font size="2" color="#FFFFFF"><b>Address:</b> <font size="2" color="#E4705F">' . ($myrow['City'] == '' ? 'N/A' : $myrow['City']) . '</font></td>
</tr>
');
More info on the ternary operator can be found here (http://us2.php.net/manual/en/language.operators.comparison.php).
Ben Rogers
10-25-2004, 08:14 PM
You might want to look into PHP's empty() (http://us2.php.net/empty) function.