mikegarey Posted June 7, 2012 Share Posted June 7, 2012 Our group was fortunate to have a veteran programmer(C and Perl) help us get started with our website but he is no longer available and we have quite a few changes and updates that need to be done. So far we have been able to handle all the changes and updates and fix or change code but we are stumped on this one. a. fldStationID and $StationID refer to a facility and are an integer of no more than 4 digits. b. Notes are recorded for each facility in tblStationNotes c. #3 below displays a table with Edit and Delete hrefs for each note. d. #2 below sets up the db acess to pull the notes and calls some functions in #1 e. Code is probably more complex than it needs to be e. Display in #3 works as planned execept it displays all notes/comments for all facilitiesa and we want to display for only one f. fldStationID or the GET variable $StationID would allow us to use a WHERE clause in the query SELECT in #2 to filter for just one facility g. And this is where we are stuck. We cannot find a way to pass StationID from #3 into #2 to filter for just one facility. Have tried Session vars and POST vars and several other ways but no luck. Suspect it has something to do with an array being used but we have just run out of brain bytes. We plan to rewrite this section but for now we need some kind of work-around until we get to rewrite. Any suggestions??? __________________________________________________________________________________ 1. ATSdb.php //... abstract class ATSdb { protected $link; protected $table; // Constructor method. // ------------------------------------------------- function __construct() { $this->connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); } //.... ___________________________________________________________________________________ 2. ATSnotes.php //... require_once('ATSdb.php'); //... class ATSnotes extends ATSdb //... function getNotes() { $col = $this->getColumnNames(); if (count($col) > 0) { //TODO Set ORDER BY to col[1] fldLevel - functions as a visible ID number and used for sort among station officials, will always be unique //TODO fix the ORDER BY to get the desired result //TODO have reset sort order to col[2] this may conflict with other places using this function //******What we need is the next line to have a WHERE clause filtering on the fldStationID or $col[1] $yada = $this->query("SELECT * FROM " . $this->getTableName() . " ORDER BY $col[2] DESC, $col[2] DESC"); while( $result = $this->fetch_array($yada)) { $array[] = $result; } } else unset ($array); return $array; } _____________________________________________________________________________________ 3. stationNotesEditDel.php //.... //Station db ID $StationID = ($_GET['vID']); $StationID = trim($StationID); $StationID = strip_tags($StationID); // Connect to the database require_once('/home/content/m/i/k/mikegarey/html/tables/ATSnotes.php'); $db = new ATSnotes(); unset ($dada); $dada = $db->getNotes(); $colNames = $db->getColumnNames(); //.... if ($dada) { // If there are some results if ($dada) { // Let's show some info echo '<p>Note Types: <font color="red">S-Safety Issue <font color="black">I-Issue/Problem <font color="blue">A-Achievement<font color="black"></p>'; echo '<table>'; echo '<tr>'; echo '<th>' . $colNames[2] . '</th>'; echo '<th>' . $colNames[3] . '</th>'; echo '<th>' . $colNames[4] . '</th>'; echo '<th>' . $colNames[5] . '</th>'; echo '<th>' . $colNames[6] . '</th>'; echo '<th>Edit</th>'; echo '<th>Delete</th>'; echo '</tr>'; // Ok, let's show the data // TODO Need code Put legend for S/I/A at top of table and also display in red/black/blue foreach ($dada as $row) { //TODO Figure why font did not change color and also add black and blue for I and A items if (stripslashes($row[2]) == 'S') { echo '<font color="red">'; } echo '<tr>'; echo '<td><center>'. stripslashes($row[2]) .'</center></td>'; echo '<td>'. stripslashes($row[3]) .'</td>'; echo '<td><center>'. stripslashes($row[4]) .'</center></td>'; echo '<td>'. stripslashes($row[5]) .'</td>'; echo '<td>'. stripslashes($row[6]) .'</td>'; echo '<td><center><a href="/tables/stationNotesEdit.php?id=' . ($row[0]) . '">'; echo '<img src="/images/Edit.jpg" width="20" height="20" border="0" title="Edit" alt="Edit" />'; echo '</center></td>'; echo '<td><center><a href="/tables/stationNotesDelete.php?id=' . ($row[0]) . '">'; echo '<img src="/images/Delete.jpg" width="20" height="20" border="0" title="Delete" alt="Del" </a></td>'; echo '</center></tr>'; } echo '</table>'; } else { echo 'There are no results to display. Odd how we connected to this database and there is no data.'; } // end else } //... Quote Link to comment https://forums.phpfreaks.com/topic/263794-trying-to-pass-a-variable-from-one-file-to-another-and-cannot-make-it-work/ Share on other sites More sharing options...
ejay Posted June 7, 2012 Share Posted June 7, 2012 This might work -------------------------------------- ATSnotes.php class ATSnotes extends ATSdb //... function getNotes($stationID = 0) { $col = $this->getColumnNames(); if (count($col) > 0) { //... $yada = $this->query("SELECT * FROM " . $this->getTableName() . ($stationID > 0? " WHERE fldStationID = $stationID " : '') . " ORDER BY $col[2] DESC, $col[2] DESC"); //... _________________________________________________ ____________________________________ 3. stationNotesEditDel.php //... //... unset ($dada); $dada = $db->getNotes($StationID); //... //... Quote Link to comment https://forums.phpfreaks.com/topic/263794-trying-to-pass-a-variable-from-one-file-to-another-and-cannot-make-it-work/#findComment-1351832 Share on other sites More sharing options...
mikegarey Posted June 7, 2012 Author Share Posted June 7, 2012 Ejay Thanks for the quick response. Unfortunately, it did not work. The good news is that with all the changes there were no errors. I looked at the table in the db and cannot see any changes. All of the fixes I attempted cause Fatal Errors. Had a problem on another page where arrays were involved and had to force a var into the array so we could use it. That was on the smae page. Am thinking that there is a similar situation here. Just don't know how to attack it. Thanks Mike Quote Link to comment https://forums.phpfreaks.com/topic/263794-trying-to-pass-a-variable-from-one-file-to-another-and-cannot-make-it-work/#findComment-1351960 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.