| | |
query behaving funny
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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
Should it have been like this?
add_time() function call::
Even though the function has been declared just beneath the function call statement, it still gives fatal error.
php Syntax (Toggle Plain Text)
$endt =array(0 => "value"); elseif (!$count=0) { while ($e_row = mysql_fetch_array($result)) { $status = 'busy'; // print the list into a table echo "<tr>"; echo "<td>" . $e_row['fName'] . $e_row['lName'] . "</td>"; echo "<td>" . $e_row['event_date'] . "</td>"; echo "<td>" . $e_row['timeStart'] . "</td>"; echo "<td>" . $e_row['agenda'] . "</td>"; echo "<td>" . $status ."</td>"; // $_SESSION array to accept 'event' emp_no & timeEnd //global $endt; //$endt=array($e_row['emp_no'] => $e_row['timeEnd']); $_SESSION['$endt']= array($e_row['emp_no'] => $e_row['timeEnd']); } }
Should it have been like this?
php Syntax (Toggle Plain Text)
// $_SESSION array to accept 'event' emp_no & timeEnd global $endt; $endt=array($e_row['emp_no'] => $e_row['timeEnd']); //$_SESSION['$endt']= array($e_row['emp_no'] => $e_row['timeEnd']); $_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.
php Syntax (Toggle Plain Text)
function max_time() { // find out the highest figure in the array for the timeEnd, then add 100 for the next hour //$_SESSION['$endt']= array($e_row['emp_no'] => $e_row['timeEnd']); //foreach ($_SESSION['$endt'] as $key => $val) FOREACH($_SESSION['$endt'] as $key => $val) { if ($val == max($_SESSION['$endt'])) { $_SESSION['my_key'] = $key; } } add_time(); } function add_time() { // increase the time to 1 hour forward $_SESSION['my_key'] = $_SESSION['my_key'] + 100; if ($_SESSION['my_key'] > 1700) { // discard scan plus writing record - pass control to abandon }elseif ($_SESSION['my_key']<= 1700) { // do the new scan scan(); } }
It is NO SHAME to ask when you want to LEARN, but FOOLISH to behave knowledgeable when YOU DON'T.
Keep PEACE alive!
Keep PEACE alive!
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?
php Syntax (Toggle Plain Text)
<?php session_start(); // This prg automatically fixes a meeting after a scan for free slots //get the list from //$_SESSION['check_array'] for the emp_no's class Mfix{ function db() { $met = mysql_connect("","",""); if (!$met) { die('Could not connect: ' . mysql_error()); } mysql_select_db("", $met); } function max_time() { // find out the highest figure in the array for the timeEnd, then add 100 for the next hour //$_SESSION['$endt']= array($e_row['emp_no'] => $e_row['timeEnd']); //foreach ($_SESSION['$endt'] as $key => $val) FOREACH($_SESSION['$endt'] as $key => $val) { if ($val == max($_SESSION['$endt'])) { $_SESSION['my_key'] = $key; } } add_time(); } function add_time() { // increase the time to 1 hour forward $_SESSION['my_key'] = $_SESSION['my_key'] + 100; if ($_SESSION['my_key'] > 1700) { // discard scan plus writing record - pass control to abandon }elseif ($_SESSION['my_key']<= 1700) { // do the new scan scan(); } } function scan() { // connect to db db(); //accept variables FOREACH ($_SESSION['check_array'] as $check_array) { $e_date = $_SESSION['meet_date']; $s_time = $_SESSION['my_key']; // new value for timeEnd //$emp_no = $check_array; /** * query the db */ $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.'"'; $result = mysql_query($sql) or die(mysql_error()); // check for num_row_count if > 0 means trouble $crazy=mysql_num_rows($result); if ($crazy==0) { // insert record into event write_meet(); }elseif($crazy>0) { // check value of $_SESSION['my_key'] if ($_SESSION['my_key'] >= 1700) { // end of the road - report can't continue with auto fix unless date is changed popup(); }elseif ($_SESSION['my_key']< 1700) { //go back and add extra hour b4 scanning add_time(); } } } function write_meet() { // connect to db db(); // declare variable to count number of records inserted $_SESSION['kount']=1; // accept the $_SESSION variables FOREACH ($_SESSION['check_array'] as $check_array){ $event_date = $_SESSION['meet_date']; $timeStart = $_SESSION['stime']; $timeEnd = $_SESSION['etime']; $location = $_SESSION['locate']; $agenda = $_SESSION['mdescription']; $emp_no = $check_array; $originator = $_SESSION['emp_numb']; /** * insert the above details into the db */ $sql="INSERT INTO event ( event_id, event_date, timeStart, timeEnd, location, agenda, emp_no, originator) VALUES ('Null','$event_date','$timeStart','$timeEnd','$location','$agenda','$emp_no','$originator')"; $_SESSION['kount']++; } // close db if (!mysql_query($sql,$met)) { die('Error: ' . mysql_error()); } mysql_close($met); echo "\n\n\t\t\t\t\t\t\t\tRecord Added"; // send control to monthly.php header('location:my_meeting.php'); } function popup() { // pop up window after pressing ok send control to my_meeting for change of date. echo "\n\n\t\t\t\tSorry, Auto Fix of your Meeting request\n"; echo "\t\t\t\tIs not Possible until you change\n"; echo "\t\t\t\tyour date for the event "; ?> <html> <form method="post" action="my_meeting.php"> <p><input type="submit" name="fix_eror" value="OK"></p></form> </html> <?php } } } ?>
It is NO SHAME to ask when you want to LEARN, but FOOLISH to behave knowledgeable when YOU DON'T.
Keep PEACE alive!
Keep PEACE alive!
Ahh ok. So these function are class methods?
To call a method you have to do:
Also, one thing I don't really get.
You have a
What exactly is that?
This seems strange, because it looks like you are trying to using the value of the
If you add a
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
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
$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.
unfortunately there is an error::
Fatal error: Call to undefined method Mfix::write_meet()
from this line
php Syntax (Toggle Plain Text)
if ($crazy==0) { // insert record into event $this->write_meet(); }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!
Keep PEACE alive!
I am posting the Mfix class
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.
php Syntax (Toggle Plain Text)
class Mfix{ function db() { $met = mysql_connect("","",""); if (!$met) { die('Could not connect: ' . mysql_error()); } mysql_select_db("", $met); } function max_time() { FOREACH($_SESSION['$endt'] as $key => $val) { if ($val == max($_SESSION['$endt'])) { $_SESSION['my_key'] = $key; } } $this->add_time(); } function add_time() { }elseif ($_SESSION['my_key']<= 1700) { // do the new scan $this->scan(); } } function scan() { // connect to db $this->db(); /** * query the db */ $crazy=mysql_num_rows($result); if ($crazy==0) { // insert record into event $this->write_meet(); }elseif($crazy>0) { // check value of $_SESSION['my_key'] if ($_SESSION['my_key'] >= 1700) { // end of the road - report can't continue with auto fix unless date is changed $this->popup(); }elseif ($_SESSION['my_key']< 1700) { //go back and add extra hour b4 scanning $this->add_time(); } } } function write_meet() { // connect to db $this->db(); // declare variable to count number of records inserted // accept the $_SESSION variables etc } function popup() { // after pressing ok send control to meeting for change of date. etc } } }
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!
Keep PEACE alive!
![]() |
Other Threads in the PHP Forum
- Previous Thread: sending the a combo box to another form
- Next Thread: how to share primary key?
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date directory display dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web webdesign websphere white xml youtube





