Jump to content


Photo

Error in Script


  • Please log in to reply
4 replies to this topic

#1 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 03 October 2006 - 10:28 AM

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


Main_Page.php
<?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);

?>


Job_List.php
<?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);
?>


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

"Whats wrong with the cat?" - Mrs Schrödinger

#2 yonta

yonta
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 03 October 2006 - 10:43 AM

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.
do it, do it right, do it right now

#3 thedarkwinter

thedarkwinter
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts
  • LocationLondon

Posted 03 October 2006 - 10:48 AM

Hi

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

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
Remember - if you don't figure it out yourself, you'll probably forget it tomorrow :)

#4 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 03 October 2006 - 10:53 AM

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.
"Whats wrong with the cat?" - Mrs Schrödinger

#5 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 03 October 2006 - 11:02 AM

hi thedarkwinter,
I've tried you suggestions and you've fixed it!!  ;D Thank you guys!
;D ;D


"Whats wrong with the cat?" - Mrs Schrödinger




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users