Reply to Re: Problems with Elseif

Your name:

Reply:


Posted by J.O. Aho on 10/18/07 18:17

Jerry Stuckle wrote:
> J.O. Aho wrote:
>> Jerry Stuckle wrote:
>>> 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.
>>>>
>>>> $result = mysql_query($query) or die ('Error in query: $query. ' .
>>>> mysql_error());
>>>>
>>>> echo '<table border=1 cellpadding=10>';
>>>>
>>>> while($row = mysql_fetch_object($result))
>>>>
>>>> {
>>>> $priority = $row['priority'];
>>
>>> Maybe it should be
>>>
>>> if ($priority == 1) ...
>>>
>>> And J.O.'s suggestion to use switch is good.
>>>
>> The $row is a object, and he tries to use it as an array, so
>> $priority is
>> nothing/null, which mean it never can be 1,2 and therefore always will
>> fall in
>> the last else-statement.
>>
>
> Ah, I missed that one. Good catch! I just always use
> mysql_fetch_array(). :-)

Thats the most common one I use, but nowadays I been more using mysqli, but
when writing soap server stuff, I have run into trouble of using mysqli and
have in those use mysql instead. So I compile always php with both mysql and
mysqli support, at least until I have rewritten all old scripts and the soap
trouble is solved somehow.


--

//Aho

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация