query behaving funny

Reply

Join Date: Sep 2008
Posts: 50
Reputation: jackakos is an unknown quantity at this point 
Solved Threads: 0
jackakos's Avatar
jackakos jackakos is offline Offline
Junior Poster in Training

Re: query behaving funny

 
0
  #11
Nov 7th, 2008
Since I have Session already started in the pages, I decided to use session instead of global and the error is gone. I did a print of the $_session['$endt'] but had only one record as the output, infact the last row. This is how I used the session
  1. $endt =array(0 => "value");
  2.  
  3. elseif (!$count=0)
  4. {
  5. while ($e_row = mysql_fetch_array($result))
  6. {
  7. $status = 'busy';
  8. // print the list into a table
  9. echo "<tr>";
  10. echo "<td>" . $e_row['fName'] . $e_row['lName'] . "</td>";
  11. echo "<td>" . $e_row['event_date'] . "</td>";
  12. echo "<td>" . $e_row['timeStart'] . "</td>";
  13. echo "<td>" . $e_row['agenda'] . "</td>";
  14. echo "<td>" . $status ."</td>";
  15.  
  16. // $_SESSION array to accept 'event' emp_no & timeEnd
  17. //global $endt;
  18. //$endt=array($e_row['emp_no'] => $e_row['timeEnd']);
  19. $_SESSION['$endt']= array($e_row['emp_no'] => $e_row['timeEnd']);
  20. }
  21. }

Should it have been like this?
  1. // $_SESSION array to accept 'event' emp_no & timeEnd
  2. global $endt;
  3. $endt=array($e_row['emp_no'] => $e_row['timeEnd']);
  4. //$_SESSION['$endt']= array($e_row['emp_no'] => $e_row['timeEnd']);
  5. $_SESSION['$endt']= $endt;

add_time() function call::
Even though the function has been declared just beneath the function call statement, it still gives fatal error.
  1. function max_time()
  2. {
  3. // find out the highest figure in the array for the timeEnd, then add 100 for the next hour
  4. //$_SESSION['$endt']= array($e_row['emp_no'] => $e_row['timeEnd']);
  5. //foreach ($_SESSION['$endt'] as $key => $val)
  6. FOREACH($_SESSION['$endt'] as $key => $val)
  7. {
  8. if ($val == max($_SESSION['$endt']))
  9. {
  10. $_SESSION['my_key'] = $key;
  11. }
  12. }
  13.  
  14. add_time();
  15. }
  16.  
  17. function add_time()
  18. {
  19. // increase the time to 1 hour forward
  20. $_SESSION['my_key'] = $_SESSION['my_key'] + 100;
  21.  
  22. if ($_SESSION['my_key'] > 1700)
  23. {
  24. // discard scan plus writing record - pass control to abandon
  25.  
  26. }elseif ($_SESSION['my_key']<= 1700)
  27. {
  28. // do the new scan
  29. scan();
  30. }
  31. }
It is NO SHAME to ask when you want to LEARN, but FOOLISH to behave knowledgeable when YOU DON'T.
Keep PEACE alive!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 50
Reputation: jackakos is an unknown quantity at this point 
Solved Threads: 0
jackakos's Avatar
jackakos jackakos is offline Offline
Junior Poster in Training

Re: query behaving funny

 
0
  #12
Nov 7th, 2008
I am posting the entire code, I tried to comment out the function call for add_time(); however, another function was next reported. can somebody look at the code below and offer advise?

  1. <?php
  2. session_start();
  3. // This prg automatically fixes a meeting after a scan for free slots
  4. //get the list from //$_SESSION['check_array'] for the emp_no's
  5.  
  6.  
  7. class Mfix{
  8.  
  9. function db()
  10. {
  11. $met = mysql_connect("","","");
  12. if (!$met)
  13. {
  14. die('Could not connect: ' . mysql_error());
  15. }
  16. mysql_select_db("", $met);
  17.  
  18.  
  19. }
  20.  
  21. function max_time()
  22. {
  23. // find out the highest figure in the array for the timeEnd, then add 100 for the next hour
  24. //$_SESSION['$endt']= array($e_row['emp_no'] => $e_row['timeEnd']);
  25. //foreach ($_SESSION['$endt'] as $key => $val)
  26. FOREACH($_SESSION['$endt'] as $key => $val)
  27. {
  28. if ($val == max($_SESSION['$endt']))
  29. {
  30. $_SESSION['my_key'] = $key;
  31. }
  32. }
  33.  
  34. add_time();
  35. }
  36.  
  37. function add_time()
  38. {
  39. // increase the time to 1 hour forward
  40. $_SESSION['my_key'] = $_SESSION['my_key'] + 100;
  41.  
  42. if ($_SESSION['my_key'] > 1700)
  43. {
  44. // discard scan plus writing record - pass control to abandon
  45.  
  46.  
  47.  
  48. }elseif ($_SESSION['my_key']<= 1700)
  49. {
  50.  
  51.  
  52. // do the new scan
  53. scan();
  54. }
  55.  
  56.  
  57. }
  58.  
  59. function scan()
  60. {
  61. // connect to db
  62. db();
  63.  
  64.  
  65. //accept variables
  66. FOREACH ($_SESSION['check_array'] as $check_array)
  67. {
  68. $e_date = $_SESSION['meet_date'];
  69. $s_time = $_SESSION['my_key']; // new value for timeEnd
  70. //$emp_no = $check_array;
  71.  
  72. /**
  73.   * query the db
  74.   */
  75. $sql = 'SELECT staff.emp_no, staff.fName, staff.lName, event.event_date, event.timeStart, event.timeEnd, event .emp_no, event.agenda FROM `staff`, `event` WHERE staff.emp_no = event.emp_no AND event.emp_no = "' .$check_array.'" AND event.event_date = "'.$e_date.'" AND event.timeStart = "'.$s_time.'"';
  76.  
  77. $result = mysql_query($sql) or die(mysql_error());
  78.  
  79. // check for num_row_count if > 0 means trouble
  80. $crazy=mysql_num_rows($result);
  81.  
  82. if ($crazy==0)
  83. { // insert record into event
  84. write_meet();
  85. }elseif($crazy>0)
  86. {
  87. // check value of $_SESSION['my_key']
  88. if ($_SESSION['my_key'] >= 1700)
  89. {
  90. // end of the road - report can't continue with auto fix unless date is changed
  91. popup();
  92. }elseif ($_SESSION['my_key']< 1700)
  93. {
  94. //go back and add extra hour b4 scanning
  95. add_time();
  96. }
  97.  
  98. }
  99.  
  100.  
  101. }
  102.  
  103. function write_meet()
  104. { // connect to db
  105. db();
  106.  
  107. // declare variable to count number of records inserted
  108. $_SESSION['kount']=1;
  109.  
  110. // accept the $_SESSION variables
  111. FOREACH ($_SESSION['check_array'] as $check_array){
  112.  
  113. $event_date = $_SESSION['meet_date'];
  114. $timeStart = $_SESSION['stime'];
  115. $timeEnd = $_SESSION['etime'];
  116. $location = $_SESSION['locate'];
  117. $agenda = $_SESSION['mdescription'];
  118. $emp_no = $check_array;
  119. $originator = $_SESSION['emp_numb'];
  120.  
  121. /**
  122.   * insert the above details into the db
  123.   */
  124.  
  125. $sql="INSERT INTO event ( event_id, event_date, timeStart, timeEnd, location, agenda, emp_no, originator)
  126. VALUES
  127. ('Null','$event_date','$timeStart','$timeEnd','$location','$agenda','$emp_no','$originator')";
  128.  
  129. $_SESSION['kount']++;
  130.  
  131. }
  132.  
  133. // close db
  134. if (!mysql_query($sql,$met))
  135. {
  136. die('Error: ' . mysql_error());
  137. }
  138. mysql_close($met);
  139.  
  140. echo "\n\n\t\t\t\t\t\t\t\tRecord Added";
  141.  
  142. // send control to monthly.php
  143. header('location:my_meeting.php');
  144. }
  145.  
  146. function popup()
  147. {
  148. // pop up window after pressing ok send control to my_meeting for change of date.
  149. echo "\n\n\t\t\t\tSorry, Auto Fix of your Meeting request\n";
  150. echo "\t\t\t\tIs not Possible until you change\n";
  151. echo "\t\t\t\tyour date for the event ";
  152.  
  153. ?>
  154. <html>
  155. <form method="post" action="my_meeting.php">
  156. <p><input type="submit" name="fix_eror" value="OK"></p></form>
  157. </html>
  158. <?php
  159. }
  160.  
  161. }
  162. }
  163.  
  164. ?>
It is NO SHAME to ask when you want to LEARN, but FOOLISH to behave knowledgeable when YOU DON'T.
Keep PEACE alive!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 444
Reputation: Atli is on a distinguished road 
Solved Threads: 56
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training

Re: query behaving funny

 
0
  #13
Nov 8th, 2008
Ahh ok. So these function are class methods?
To call a method you have to do: $object->method() , rather than just: method() So in your case, change the: add_time(); call to: $this->add_time();
Also, one thing I don't really get.
You have a $_SESSION['$endt'] variable.
What exactly is that?

This seems strange, because it looks like you are trying to using the value of the $endt variable as the key, but you are surrounding it with single-quotes, which makes it literally use the text $endt as the key value rather the the value of the $endt variable.

If you add a var_dump($_SESSION['$endt']); in your max_time function, before the foreach loop, what does that output?
Last edited by Atli; Nov 8th, 2008 at 5:09 am. Reason: Spelling
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 50
Reputation: jackakos is an unknown quantity at this point 
Solved Threads: 0
jackakos's Avatar
jackakos jackakos is offline Offline
Junior Poster in Training

Re: query behaving funny

 
0
  #14
Nov 8th, 2008
I have done the correction and inserted var_dump($_SESSION['$endt']);

unfortunately there is an error::
Fatal error: Call to undefined method Mfix::write_meet()

from this line
  1. if ($crazy==0)
  2. { // insert record into event
  3. $this->write_meet();
  4. }elseif($crazy>0)

$this->write_meet(); is causing the error. Very strange as the other class methods call functions are working, at lest they haven't shown an error yet.
It is NO SHAME to ask when you want to LEARN, but FOOLISH to behave knowledgeable when YOU DON'T.
Keep PEACE alive!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 444
Reputation: Atli is on a distinguished road 
Solved Threads: 56
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training

Re: query behaving funny

 
0
  #15
Nov 10th, 2008
Where is that piece of code located? Inside the Mfix class?

Does the Mfix class have a write_meet() method?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 50
Reputation: jackakos is an unknown quantity at this point 
Solved Threads: 0
jackakos's Avatar
jackakos jackakos is offline Offline
Junior Poster in Training

Re: query behaving funny

 
0
  #16
Nov 10th, 2008
Yes it does.
It is NO SHAME to ask when you want to LEARN, but FOOLISH to behave knowledgeable when YOU DON'T.
Keep PEACE alive!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 444
Reputation: Atli is on a distinguished road 
Solved Threads: 56
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training

Re: query behaving funny

 
0
  #17
Nov 12th, 2008
That makes no sense.

PHP says: Call to undefined method Mfix::write_meet() . Therefore, Mfix does not have a write_meet method.
PHP does not lie.

Make sure the spelling is correct and that you didn't accidentally put the method into the wrong place.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 50
Reputation: jackakos is an unknown quantity at this point 
Solved Threads: 0
jackakos's Avatar
jackakos jackakos is offline Offline
Junior Poster in Training

Re: query behaving funny

 
0
  #18
Nov 12th, 2008
I am posting the Mfix class

  1. class Mfix{
  2.  
  3. function db()
  4. {
  5. $met = mysql_connect("","","");
  6. if (!$met)
  7. {
  8. die('Could not connect: ' . mysql_error());
  9. }
  10. mysql_select_db("", $met);
  11.  
  12. }
  13.  
  14. function max_time()
  15. {
  16. FOREACH($_SESSION['$endt'] as $key => $val)
  17. {
  18. if ($val == max($_SESSION['$endt']))
  19. {
  20. $_SESSION['my_key'] = $key;
  21. }
  22. }
  23.  
  24. $this->add_time();
  25. }
  26.  
  27. function add_time()
  28. {
  29. }elseif ($_SESSION['my_key']<= 1700)
  30. {
  31. // do the new scan
  32. $this->scan();
  33. }
  34. }
  35. function scan()
  36. {
  37. // connect to db
  38. $this->db();
  39.  
  40. /**
  41.   * query the db
  42.   */
  43. $crazy=mysql_num_rows($result);
  44.  
  45. if ($crazy==0)
  46. { // insert record into event
  47. $this->write_meet();
  48. }elseif($crazy>0)
  49. {
  50. // check value of $_SESSION['my_key']
  51. if ($_SESSION['my_key'] >= 1700)
  52. {
  53. // end of the road - report can't continue with auto fix unless date is changed
  54. $this->popup();
  55. }elseif ($_SESSION['my_key']< 1700)
  56. {
  57. //go back and add extra hour b4 scanning
  58. $this->add_time();
  59. }
  60. }
  61. }
  62. function write_meet()
  63. { // connect to db
  64. $this->db();
  65.  
  66. // declare variable to count number of records inserted
  67. // accept the $_SESSION variables
  68. etc
  69. }
  70. function popup()
  71. {
  72. // after pressing ok send control to meeting for change of date.
  73. etc
  74. }
  75. }
  76. }

I just copied the whole class and deleted the logic since it was taken up much space - just wanted to show the calling methods and the functions as they are.
It is NO SHAME to ask when you want to LEARN, but FOOLISH to behave knowledgeable when YOU DON'T.
Keep PEACE alive!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC