|
Posted by J.O. Aho on 10/18/07 16:33
Alec wrote:
> What am I doing wrong with this elseif condition?
>
> $query = "SELECT company, priority FROM companyid_uks49179 WHERE
> town='Bury St. Edmunds' AND category='sleep' AND priority IN
> ('1', '2', '3') ORDER BY priority";
>
> This returns a result set of a number of companies with different
> priority numbers from 1 to 3. see webpage http://www.freeweekends.co.uk/test3.php
>
> I now want to create a table result for each one, with an 'elseif'
> statement creating a different effect for each of the three different
> priorities.
I'm that much into usage of else if when I have this kind of options, I
suggest you try out a switch.
> $result = mysql_query($query) or die ('Error in query: $query. ' .
> mysql_error());
>
> echo '<table border=1 cellpadding=10>';
>
> while($row = mysql_fetch_object($result)) {
//No values are in an array['priority'], they are in an object->priority;
switch($row->priority) {
case '1':
$type='test1';
break;
case '2':
$type='test2';
break;
case '3':
$type='test3';
break;
default:
$type='unknown';
break;
}
echo "<tr>\n<td>{$row->company}</td>\n</tr>\n";
echo "<tr>\n<td>{$type}</td>\n</td>\n";
>
> }
> echo '</table>';
You may have to take a better look at your indentation and your html validity.
Don't duplicate code when you can have it once, this way you can make your
code shorter, functions will be a good thing to use if you have same code that
you need to use in different places.
--
//Aho
Navigation:
[Reply to this message]
|