You are here: Re: Little script error « PHP Programming Language « IT news, forums, messages
Re: Little script error

Posted by Jerry Stuckle on 03/04/07 19:36

brian.swan@gmail.com wrote:
> On Mar 4, 11:43 am, "Mikro" <i...@elektroonika.com> wrote:
>> Hi!
>>
>> My problem is at the end of script. When "if (!empty($bensiin_2["id"]))" is
>> emtpty (id doesn't exist) then else doesn't echo. Maybe the problem is in
>> html code?
>>
>> {
>> $peavik=("SELECT * FROM soidup_info order by id");
>> $paevik = mysql_query($peavik);
>> while($paevik_2 = mysql_fetch_array($paevik))
>> {echo"
>> <table border=1 width=100% >
>> <tr>
>> <td width=81>"; ?><A
>> onclick="window.open('xxx.php?raha=<? echo $paevik_2["id"];
>> ?>','','width=480,height=190,scrollbars=no')"
>> href="javascript:;"><span class=link><? echo" ".date("d-m-Y",
>> strtotime($paevik_2["kuup"]))." ";?></span></td>
>> <? echo"
>> <td width=250>".$paevik_2["marsruut"]."</td>
>> <td width=200>".$paevik_2["pohjus"]."</td>
>> <td width=153>".$paevik_2["juht"]."</td>
>> <td width=80 align=center>".$paevik_2["alg"]."</td>
>> <td width=80 align=center>".$paevik_2["lopp"]."</td>";
>>
>> $bents=("SELECT * FROM soidup_bensiin where u_id=".$paevik_2["id"]."");
>> $bensiin = mysql_query($bents);
>> while($bensiin_2 = mysql_fetch_array($bensiin)) {
>> if (!empty($bensiin_2["id"]))
>> {
>> echo"<td align=center>".$bensiin_2["kogus"]."L</td></tr>"; }
>> else {echo" <td align=center>pole midagi</td> </tr>"; }
>>
>> }
>>
>> }
>> }
>
> Try doing a print_r( $bensiin_2 );. That should output everything in
> the current array. Also, you are not checking for the number of rows
> or any errors being returned by MySQL. This is a large boo-boo. It
> could be that no rows are returned at all so the condition would never
> get reached.
>
> Hope this helps,
> Brian Swan
> http://www.usedboatyard.com
>

It's not necessary to check for the number of rows returned - if none
are returned, the first iteration of the while() loop will fail. It's
perfectly good code.

However, I do agree one should check the results of the mysql_query()
just to ensure it returned a valid result set (which may or may not be
empty). That needs to be the first step - this could, for instance, be
a syntax error in the SQL.

As to the original problem the problem - after checking to see if mysql
actually returned a valid result, zorro's suggestion is good. Also,
what is the definition of the soidup_bensiin table, and the contents of
'id' you expect to be returned?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this 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

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