Jump to content

Archived

This topic is now archived and is closed to further replies.

Fearpig

Error in Script

Recommended Posts

Hello everyone,
Could someone take a look at my code for me and suggest where I'm going wrong?


Main_Page.php
[code]
<?php

$conn=odbc_connect('OU_PROD','ou_dba','dba');
if (!$conn)
      {exit("Connection Failed: " . $conn);}
$sql="SELECT * FROM person WHERE person_group = 'ENGINEER'";
$rs=odbc_exec($conn,$sql);
if (!$rs)
      {exit("Error in SQL");}

echo "<Table cellspacing='0' cellpadding='0' border='1'><tr>";
//echo "$day<br>";

while (odbc_fetch_row($rs))
{
    $User_ID=odbc_result($rs,"user_id");
    echo "<td>$User_ID";
    include 'Job_List.php';
    // ------------ This is where the script breaks ---------
    echo "<td>";
}

echo "</tr></table>";
odbc_close($conn);

?>
[/code]


Job_List.php
[code]
<?php

$day=0;
//sets the day value back to 0 - days run 0,1,2,3,4,5,6,

$startdate=date("Y/m/d");
//sets the initial date to the current date

echo "<Table border=1 width=200>";

//echo "<p>$day<br>";
//echo "$startdate<p>";

while ($day < 7)
{
     
      $selectdate = date( "Ymd", mktime(0, 0, 0, date("m"), date("d")+$day, date("y")) );
      //increase $startdate by the current value of $day

      $formatdate = date("l - d/m/Y",strtotime("$selectdate"));

      $conn=odbc_connect('OU_PROD','ou_dba','dba');
      if (!$conn)
            {exit("Connection Failed: " . $conn);}
      $sql="SELECT * FROM assignment WHERE promised_begin_dt = '$selectdate' and person_id = '$User_ID'";
      $rs=odbc_exec($conn,$sql);
      if (!$rs)
            {exit("Error in SQL");}

      echo "<tr bgcolor=#CCCCCC align=center class='Body2'><th><b>$formatdate</b></th></tr><tr><td>";
  //echo "$day<br>";

    while (odbc_fetch_row($rs))
    {
          $Request=odbc_result($rs,"request_id");
          echo "<a href=Result_ByRequest.php?Request=$Request class='Body2'>$Request</a><br>";
    }



$day++;
//fairly sure that this won't work as it refers to itself!

}

echo "</td></tr></Table>";
odbc_close($conn);
?>
[/code]


If I comment out the line "include 'Job_List.php';" on the main page then the table of engineers names is created correctly with a new column for each engineer. When the Job_List.php is included it writes the first column correctly but then gives the error shown below:

Warning: odbc_fetch_row(): 11 is not a valid ODBC result resource in D:\Intranet v3\TEST\Service\Main_Page.php on line 15

Line 15 is: "while (odbc_fetch_row($rs))"


If anyone can spot where its breaking down I would appreciate it as this is the most complex thing I've attempted and so far I've failed at the very last hurdle!!

Cheers
Tom

Share this post


Link to post
Share on other sites
Are you sure this query actually returns anything?

SELECT * FROM assignment WHERE promised_begin_dt = '$selectdate' and person_id = '$User_ID'

Replace the variables with real values and try it in phpmyaddmin. Maybe it's simply empty. You should probably check before the while if it's false (which you do) and if the number of rows returned is bigger than zero.

Share this post


Link to post
Share on other sites
Hi

ive never used the odbc - but you are using the same result variable [color=red]$rs[/color] for both queries...change the one in job_list.php the [color=red]$rs2[/color]

also, you should probably drop the line

$conn=odbc_connect('OU_PROD','ou_dba','dba');

from job_list.php as you are already connected.

cheers
tdw

Share this post


Link to post
Share on other sites
It all works seperately but when i link the two files it errors out in the second column.

When I remove the link in Main_Page.php it will create a table with a column for each engineer.
I can run Job_List.php up on its own with a constant instead of the $User_ID variable and it runs fine.

When the link is in place it creates a table with two columns the first one contains the first engineer and his job list the second column contains the error:

"Warning: odbc_fetch_row(): 11 is not a valid ODBC result resource in D:\Intranet v3\TEST\Service\test.php on line 15"

From the data I would expect four columns each with an engineer and his job list.

Share this post


Link to post
Share on other sites
hi thedarkwinter,
I've tried you suggestions and you've fixed it!!  ;D Thank you guys!
;D ;D

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.