473,382 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Little script error

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>"; }

}
}
}

Mar 4 '07 #1
4 1304
On Mar 4, 11:43 am, "Mikro" <i...@elektroonika.comwrote:
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

Mar 4 '07 #2
br********@gmail.com wrote:
On Mar 4, 11:43 am, "Mikro" <i...@elektroonika.comwrote:
>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.
js*******@attglobal.net
==================
Mar 4 '07 #3
...zorro's suggestion is good. Also...
Huh? i didn't say anything...

Mar 4 '07 #4
zorro wrote:
>...zorro's suggestion is good. Also...

Huh? i didn't say anything...
Sorry - that should be "Brian's"... Too many windows open :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andy Dixon | last post by:
Hi I have been banging my head over something for the last week and cant get around. I am trying to write a script which will log into a mailbox, retrieve each message, save the attachment...
3
by: Ron Stephens | last post by:
I posted to my web site a fun little program called merlin.py today. Please keep in mind that I am a hobbyist and this is just a little hack, if you look at the code you will see that it is still...
2
by: Jai | last post by:
hey guys, i was wondering if you could help me wit a little JS array problem, my variables are comming up "undefined", check it out for yourself... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
0
by: PeterX | last post by:
Luban: A new scripting language with C++ syntax and Java Bean like objec model Luban is a new component oriented scripting language recently created by Xiaochuan(Peter) Huang in New Jersey,...
1
by: Jon Turlington | last post by:
Maybe someone can tell me why I am getting this error. zip code form test http://localhost/zip_code_auto_update.asp Event thread: keyup Error: name: ReferenceError message: Statement on line...
37
by: John Salerno | last post by:
I contacted my domain host about how Python is implemented on their server, and got this response: ------------------- Hello John, Please be informed that the implementation of python in our...
5
eragon
by: eragon | last post by:
I am making a password script, i have most of it done, ill show you, but i hit a brick wall.... lol, I have it so when you log in it takes you to your main page, that works, but when you enter the...
15
by: Lawrence Krubner | last post by:
Does anything about this script look expensive, in terms of resources or execution time? This script dies after processing about 20 or 25 numbers, yet it leaves no errors in the error logs. This is...
14
riverdale1567
by: riverdale1567 | last post by:
Hi I am a newbie trying to get some of my first code working, yada yada yada. I have a drop down box which chooses a state then takes the post data to 'processform2.php' to use that to pull up...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.