Little script error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mikro

    Little script error

    Hi!

    My problem is at the end of script. When "if (!empty($bensii n_2["id"]))" is
    emtpty (id doesn't exist) then else doesn't echo. Maybe the problem is in
    html code?

    {
    $peavik=("SELEC T * FROM soidup_info order by id");
    $paevik = mysql_query($pe avik);
    while($paevik_2 = mysql_fetch_arr ay($paevik))
    {echo"
    <table border=1 width=100% >
    <tr>
    <td width=81>"; ?><A
    onclick="window .open('xxx.php? raha=<? echo $paevik_2["id"];
    ?>','','width=4 80,height=190,s crollbars=no')"
    href="javascrip t:;"><span class=link><? echo" ".date("d-m-Y",
    strtotime($paev ik_2["kuup"]))." ";?></span></td>
    <? echo"
    <td width=250>".$pa evik_2["marsruut"]."</td>
    <td width=200>".$pa evik_2["pohjus"]."</td>
    <td width=153>".$pa evik_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($be nts);
    while($bensiin_ 2 = mysql_fetch_arr ay($bensiin)) {
    if (!empty($bensii n_2["id"]))
    {
    echo"<td align=center>". $bensiin_2["kogus"]."L</td></tr>"; }
    else {echo" <td align=center>po le midagi</td </tr>"; }

    }
    }
    }



  • brian.swan@gmail.com

    #2
    Re: Little script error

    On Mar 4, 11:43 am, "Mikro" <i...@elektroon ika.comwrote:
    Hi!
    >
    My problem is at the end of script. When "if (!empty($bensii n_2["id"]))" is
    emtpty (id doesn't exist) then else doesn't echo. Maybe the problem is in
    html code?
    >
    {
    $peavik=("SELEC T * FROM soidup_info order by id");
    $paevik = mysql_query($pe avik);
    while($paevik_2 = mysql_fetch_arr ay($paevik))
    {echo"
    <table border=1 width=100% >
    <tr>
    <td width=81>"; ?><A
    onclick="window .open('xxx.php? raha=<? echo $paevik_2["id"];
    ?>','','width=4 80,height=190,s crollbars=no')"
    href="javascrip t:;"><span class=link><? echo" ".date("d-m-Y",
    strtotime($paev ik_2["kuup"]))." ";?></span></td>
    <? echo"
    <td width=250>".$pa evik_2["marsruut"]."</td>
    <td width=200>".$pa evik_2["pohjus"]."</td>
    <td width=153>".$pa evik_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($be nts);
    while($bensiin_ 2 = mysql_fetch_arr ay($bensiin)) {
    if (!empty($bensii n_2["id"]))
    {
    echo"<td align=center>". $bensiin_2["kogus"]."L</td></tr>"; }
    else {echo" <td align=center>po le 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


    Comment

    • Jerry Stuckle

      #3
      Re: Little script error

      brian.swan@gmai l.com wrote:
      On Mar 4, 11:43 am, "Mikro" <i...@elektroon ika.comwrote:
      >Hi!
      >>
      >My problem is at the end of script. When "if (!empty($bensii n_2["id"]))" is
      >emtpty (id doesn't exist) then else doesn't echo. Maybe the problem is in
      >html code?
      >>
      >{
      >$peavik=("SELE CT * FROM soidup_info order by id");
      >$paevik = mysql_query($pe avik);
      >while($paevik_ 2 = mysql_fetch_arr ay($paevik))
      >{echo"
      ><table border=1 width=100% >
      ><tr>
      > <td width=81>"; ?><A
      >onclick="windo w.open('xxx.php ?raha=<? echo $paevik_2["id"];
      >?>','','width= 480,height=190, scrollbars=no') "
      >href="javascri pt:;"><span class=link><? echo" ".date("d-m-Y",
      >strtotime($pae vik_2["kuup"]))." ";?></span></td>
      ><? echo"
      > <td width=250>".$pa evik_2["marsruut"]."</td>
      > <td width=200>".$pa evik_2["pohjus"]."</td>
      > <td width=153>".$pa evik_2["juht"]."</td>
      > <td width=80 align=center>". $paevik_2["alg"]."</td>
      > <td width=80 align=center>". $paevik_2["lopp"]."</td>";
      >>
      >$bents=("SELEC T * FROM soidup_bensiin where u_id=".$paevik_ 2["id"]."");
      > $bensiin = mysql_query($be nts);
      > while($bensiin_ 2 = mysql_fetch_arr ay($bensiin)) {
      > if (!empty($bensii n_2["id"]))
      > {
      >echo"<td align=center>". $bensiin_2["kogus"]."L</td></tr>"; }
      > else {echo" <td align=center>po le 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

      >
      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@attgl obal.net
      =============== ===

      Comment

      • zorro

        #4
        Re: Little script error

        ...zorro's suggestion is good. Also...
        Huh? i didn't say anything...

        Comment

        • Jerry Stuckle

          #5
          Re: Little script error

          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.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          Working...