Jump to content

cougar23

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

cougar23's Achievements

Member

Member (2/5)

0

Reputation

  1. It looks like that worked I think. Thanks to all
  2. in a definitions.inc file that I include at the top of the page. Right now debugging, the page looks like this: <!-- import common php servier-side functions library --> <?php require_once('../includes/common_fns.inc'); ?> <!-- import directory defintions file --> <?php require_once('definitions.inc'); ?> <!-- DIV TO SHOW STATUS MESSAGE, IF REQUIRED AFTER PAGE RENDERS --> <div id="statusMsgDiv"> <label id="statusMsgOutput"></label> </div> <?php //show status message if necessary after page has rendered; HARD-CODED TEST FOR NOW $_SESSION['statusMsg'] = 'LATE_NEXT_DAY_ERROR'; displayStatusMessageIfRequired($studentErrorMessages, null); ?> and then the function code in common_fns.inc is: //if key was found in the error messages array, echo javascript to show the message in RED error message color if(array_key_exists($messageKey, $errorMsgDefinitionsArray)){ echo '<script type="text/javascript">'; echo ' document.getElementById("statusMsgDiv").style.display = "block"; '; echo ' document.getElementById("statusMsgOutput").classname = "red bold"; '; echo ' document.getElementById("statusMsgOutput").value = "'.$errorMsgDefinitionsArray[$messageKey].'"; '; echo '</script>'; }
  3. I have an array of error messages with keys defined, and I want to output the message associated with a key to the screen, but my code is outputting the key. My array is like this: $studentErrorMessages = array( 'LATE_NEXT_DAY_ERROR' => 'You can not reserve an appointment for the following day after 3:00 PM. Please select another appointment', 'APPT_NOW_RESERVED_ERROR' => 'The requested appointment is no longer available. Please select a different appointment', 'CANCEL_NOT_ALLOWED' => 'You can not cancel your appointment after 3:00 PM the day before your appointment. Please email your advisor if you are unable to attend your scheduled appointment' ); And then my code to output the error message is this: //if key was found in the error messages array, echo javascript to show the message in RED error message color if(array_key_exists($messageKey, $errorMsgDefinitionsArray)){ echo '<script type="text/javascript">'; echo ' document.getElementById("statusMsgDiv").style.display = "block"; '; echo ' document.getElementById("statusMsgOutput").classname = "red bold"; '; echo ' document.getElementById("statusMsgOutput").value = "'.$errorMsgDefinitionsArray[$messageKey].'"; '; echo '</script>'; } So testing, I have set the $messageKey = 'LATE_NEXT_DAY_ERROR' and instead of displaying the error description, it's displaying 'LATE_NEXT_DAY_ERROR' . What am I doing wrong? Thanks for the help ahead of time.
  4. In and calendar/scheduling UI, I have two JS arrays (originalTimeSlots & currentTimeSlots) that store boolean values on if the checkbox for that time slot is selected or not. They are both associative arrays with the index/key being in the format "DATE;APPT_START_TIME;APPT_END_TIME", i.e. originalTimeSlots["2008-11-17;08:00:00;09:00:00"] = true; The original array holds the values of the checkboxes on load of page, while current holds the values after the user has (potentially) made changes by selected one or more slots and clicks a button to submit. What I want to do is loop through both arrays comparing the values of the matching pairs and set a variable once one is found to be different. I tried two FOR loops but the length is coming out as zero(0). How can I do what i'm trying to do? var nothingChanged = false; for(var i = 0; i < originalTimeSlots.length; i++) { for(var j = 0; j < currentTimeSlots.length; j++) { if(originalTimeSlots[i] != currentTimeSlots[j]) { nothingChanged = true; return; } } }
  5. I have a page that displays time slots people can sign up for by selecting checkboxes input elements. for the <input> tag values, the "name"'s are the same, and the values are the date and time values of the time slot. When I submit this form to the server (and have selected two or more checkboxes), only the most recently checked checkbox is coming through on my $_POST variable when it gets to the server. Here's the code I have on the page for the checkbox imput (this is inside of a loop that executes from a specified earliest time show to a latest time shown) echo '<input type="checkbox" name="timeSlot" value="'.$date.';'.$startTime.';'.$endTime.'">'; Then server side I want to view all the checkboxes selected //get the time slots the faculty member checked to be available for advising $selectedTimeSlots = $_POST['timeSlot']; echo $selectedTimeSlots; So, for example, if I selected three checkboxes for the date 2008-11-17, for the times 8:00 AM-8:30 AM, 8:30 AM-9:00 AM, 9:00 AM-9:30 AM, the output of the variable server-side ($_POST['timeSlots']) is only the 9:00 AM-9:30 AM slot. What am I doing wrong or how can I make the file do what I want to do, which is to have a collection of ALL the selected timeSlots? Thanks in advance
  6. I have used PDO do make a generic method that I call to execute SQL queries to my database (myadvisor). I have been executing my queries pulling from the STUDENT and FACULTY tables within the myadvisor database. However, when we go to production, all the info from student and faculty will come from a seperate database (human_resources). I was wondering how to do (and how I will have to modify my code) to execute a query pulling from both the myadvisor and human_resources databases? In the following example of what I have currently, the APPT info will all come from the myadvisor database, while the student info will need to come from the human_resources database, where a.STUDENT would be a foreign key of human_resouces.students on the student's ID number. Thanks for the help in advance! function getAppointments($facultyId) { require_once('../includes/DatabaseManager.inc'); $dbManager = new DatabaseManager('localhost', 'myadvisor', 'guest', 'guest'); //build query $query = 'select a.APPT_DATE, a.APPT_START_TIME, a.APPT_END_TIME, a.STUDENT, s.STUD_F_NAME, s.STUD_M_NAME, s.STUD_L_NAME from ADVISING_APPOINTMENT a, STUDENT s where a.ADVISOR = :facultyId and a.STUDENT is not null and a.STUDENT = s.CWID order by a.APPT_DATE asc, a.APPT_START_TIME asc'; $queryHolders = array(':facultyId'); $params = array($facultyId); $paramTypes = array(PDO::PARAM_INT); $results = $dbManager->doPreparedStmt($query, $queryHolders, $params, $paramTypes); return $results; } class DatabaseManager { //-----------------// // CLASS VARIABLES // //-----------------// private $dbHost; private $dbName; private $dbUser; private $dbPass; //------------------------------------------------------------------- //--------------// // CONSTRUCTORS // //--------------// public function __construct($dbHost, $dbName, $dbUser, $dbPass) { $this->dbHost = $dbHost; $this->dbName = $dbName; $this->dbUser = $dbUser; $this->dbPass = $dbPass; } public function getDatabaseHost() { return $this->dbHost; } public function setDatabaseHost($value) {$this->dbHost = value; } public function getDatabaseName() { return $this->dbName; } public function setDatabaseName($value) {$this->dbName = value; } public function getDatabaseUser() { return $this->dbUser; } public function setDatabaseUser($value) {$this->dbUser = value; } public function getDatabasePassword() { return $this->dbPass; } public function setDatabasePassword($value) {$this->dbPass = value; } //------------------------------------------------------------------- //-----------// // FUNCTIONS // //-----------// /******************************************************************* Function: doPreparedStatement Creation Date: Created By: Parameters: Returns: Description: ********************************************************************/ function doPreparedStmt($query, $queryHolders, $params, $paramTypes) { //echo $query.'<br>'; try { //establish database connection $db = new PDO("mysql:host=$this->dbHost;dbname=$this->dbName", $this->dbUser, $this->dbPass); $stmt = $db -> prepare($query); //bind the specified parameters $counter = 0; foreach($queryHolders as $q) { $stmt -> bindParam($q, $params[$counter], $paramTypes[$counter]); //echo 'binding '.$q.' to value of '.$params[$counter].'<br>'; $counter += 1; } //execute the query and return all rows resulting from the query executed $stmt -> execute(); //echo $stmt -> rowCount(); return $stmt -> fetchAll(); } catch(PDOException $e) { echo $e->getMessage(); } //finally close statment and database connection $stmt -> close(); $db = null; } //------------------------------------------------------------------- }//end class
  7. I'm using PDO and trying to bind a date parameter. For example, my parameter is '2008-08-08' and I'm trying to set that as a parameter for more query but I get "Fatal error: Undefined class constant 'PARAM_DATE' ". Any ideas why I would be getting this error? Should I just pass the date as a STR type? Would MySQL convert that to a DATE automatically, as that's what the column type in the DB is? (NOTE: i have a $dbManager object that handles my connection and loops through binding parameters, etc) $query = 'update ADVISING_APPOINTMENT a set a.STUDENT = null where a.STUDENT = :studentId and a.APPT_DATE = :apptDate and a.APPT_START_TIME = :apptStartTime and a.APPT_END_TIME = :apptEndTime'; $queryHolders = array(':studentId', ':apptDate', ':apptStartTime', 'apptEndTime'); $params = array($studentId, $apptDate, $apptStartTime, $apptEndTime); $paramTypes = array(PDO::PARAM_INT, PDO::PARAM_DATE, PDO::PARAM_TIME, PDO::PARAM_TIME); $results = $dbManager->doPreparedStmt($query, $queryHolders, $params, $paramTypes);
  8. Ok this was my code before: foreach($results as $row) { if($counter % 2 == 0) echo '<tr>'; else echo '<tr class="lightGrey">'; $counter += 1; echo '<td>'.$row['course_name'].' </td>'; echo '<td>'.$row['term_1_grade'].' </td>'; echo '<td>'.$row['term_2_grade'].' </td>'; echo '<td>'.$row['mid_term_exam'].' </td>'; echo '<td>'.$row['semester_1_grade'].' </td>'; echo '<td>'.$row['term_3_grade'].' </td>'; echo '<td>'.$row['term_4_grade'].' </td>'; echo '<td>'.$row['final_exam'].' </td>'; echo '<td>'.$row['semester_2_grade'].' </td>'; echo '<td>'.$row['course_grade'].' </td>'; echo '</tr>'; } And this is my code after, and now the table is not formatted, it's just outputting the vaules all together outside of the table, instead of in the table in the cells: foreach($results as $row) { if($counter % 2 == 0) echo '<tr>'; else echo '<tr class="lightGrey">'; $counter += 1; echo '<td>'.(!empty($row['course_name'])) ? $row['course_name'] : ' '.'</td>'; echo '<td>'.(!empty($row['term_1_grade'])) ? $row['term_1_grade'] : ' '.'</td>'; echo '<td>'.(!empty($row['term_2_grade'])) ? $row['term_2_grade'] : ' '.'</td>'; echo '<td>'.(!empty($row['mid_term_exam'])) ? $row['mid_term_exam'] : ' '.'</td>'; echo '<td>'.(!empty($row['semester_1_grade'])) ? $row['semester_1_grade'] : ' '.'</td>'; echo '<td>'.(!empty($row['term_3_grade'])) ? $row['term_3_grade'] : ' '.'</td>'; echo '<td>'.(!empty($row['term_4_grade'])) ? $row['term_4_grade'] : ' '.'</td>'; echo '<td>'.(!empty($row['semester_2_grade'])) ? $row['semester_2_grade'] : ' '.'</td>'; echo '<td>'.(!empty($row['course_grade'])) ? $row['course_grade'] : ' '.'</td>'; echo '</tr>'; } Any way to fix this so that it works via the second method?
  9. i'm building a HTML table base don the contents of a database row returned from a mysql PDO query. I have some columns that don't have data in them every time, and in the table it doens't put data in the cell and therefore messes up the look of the table because the border for the cell with missing data doesn't get output. I can fix the problem by putting whitespace in teh cell. Right now i have the following line: echo '<td>'.$row['course_name'].' </td>'; What I'd like to do is some one-liner like the following, that if the column contains no data echoes the whitespace char, otherwise the data in the column. Does anyone if this is possible and if so how to do it? echo (!empty($row['course_name']) ? $row['course_name'] : '$nbsp;';
  10. Below is like what i had in mind, but it doesn't work: function doPreparedStatement($query, $paramTypes, $params, $resultColumns) { $stmt = $db -> prepare($query); foreach($params as $param) $paramString += ', '.$param; $stmt -> bind_param($paramTypes, $paramString); $stmt -> execute(); $stmt -> store_result(); foreach($resultColumns as $resultCol) $resultColString += $resultCol.', '; $resultColString = substr($resultColString, 0, -2); $stmt -> bind_result($resultColString); return $stmt; }
  11. By a number of parameters, I mean that I want to be able to do one query like SELECT name FROM users as: $query = 'SELECT name FROM users WHERE name = ?'; $paramTypes = 's'; $params = array($name); $resultCols = array ($resultName); doPreparedStmt($query, $paramTypes, $params, $resultCols); and then be able to use the same function for a prepared stmt with two, three, four, etc parameters, such as: $query = 'SELECT state FROM operations WHERE state = ? AND city = ?'; $paramTypes = 'ss'; $params = array($state, $city); $resultCols = array ($resultState, $resultCity); doPreparedStmt($query, $paramTypes, $params, $resultCols);
  12. I'm trying to make a generalizing function to execute a MySQL prepared statement, and pass as arguments to the function the query to be executed, the bind_params data types string, the variables of the parameters to bind, and the bind_result names to bind the resulting columns to variables. I was thinking of passing each of these as arrays, and doing some type of looping through the arrays to build the actual statement(i.e., foreach($bindParam as $param), etc). The below code is wat I'm trying to make as a function. Then i'd like to pass the value of $query, "sss" (or w/e data types) of bind_param, each of the parameters, and each of the bind_result fields. require_once('db_fns.php'); if( $db = openConnection('guest', 'guest') ) { $query = 'SELECT m.member_id, password, member_type FROM member m WHERE m.member_id = ? and password = ? and member_type = ?'; //build and execute query session_start(); $stmt = $db -> prepare($query); $stmt -> bind_param("sss", $_SESSION['validUserId'], $_SESSION['validUserPassword'], $_SESSION['validUserType']); $stmt -> execute(); $stmt -> store_result(); $stmt -> bind_result($userid, $password, $validUserType); $numRows = $stmt -> num_rows; //do whatever is needed //otherwise user has permisson to access this directory //close prepared statement and database connection $stmt -> close(); closeConnection($db); With the parameters and the result columns, is there any way to make the function generic enough to be able to handle any number of parameters/columns? I was thinking something like, the following, if possible, but I dont know how to implement the actually doPreparedStmt() function: $query = 'SELECT m.member_id, password, member_type FROM member m WHERE m.member_id = ? and password = ? and member_type = ?'; $paramTypes = 'sss'; $params = array($_SESSION['validUserId'], $_SESSION['validUserPassword'], $_SESSION['validUserType']); $resultColumns = array($userid, $password, $validUserType); doPreparedStmt($query, $paramTypes, $params, $resultColumns); code]
  13. That fetch() line did it; thanks to everyone!
  14. I kno the database is populated. It has only the one entry which i'm testing. Also, the userid and password variables are being set (although they could still be set from the code prior to bind_result). I did a check and the bind_result line is returning 1/true....any other ideas as to what's going wrong?
×
×
  • Create New...

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.