Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Unable to use variable from prev page in query

Codes here !

Moderators: macek, egami, gesf

Unable to use variable from prev page in query

Postby mikegarey » Thu Jun 07, 2012 3:22 pm

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??? Suspect it has something to do with the array in the query but don't really know.
__________________________________________________________________________________
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
}

//...
mikegarey
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Jun 07, 2012 1:38 pm

Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.