Page 1 of 1

Help updating single value of returned database rows.

Posted: Mon Apr 12, 2010 6:02 pm
by gammaman
Ok I am trying to take a query from my database and take that query and put it into a form so that the user can edit value(s) and then update the database. The problem is that the form has multiple rows and so I need indexes which I am having a hard time getting. Look trough the code to see my code comments as to what I am trying to acheive.

<?php
require('../database.php');
require('../config.php');

require_once('../oracle_session.class.php');
Session::start('IRS', $php_session_database, $php_session_dbusername, $php_session_dbpassword);

// Do a SELECT query based on the current date and give user a form to change the data. Have a form where the action goes back to traintrack.php so the user can see the results.
echo '<form id="track" name="track" method="post" action="updateTrack.php">
<table width="100%">
<tr>
<th bgcolor ="yellow" colspan="5">Update Track Work</th>
</tr>
<tr>
<th>Branch</th><th>Tracks</th><th>Location</th><th>Start</th><th>Stop</th>
</tr>';
$conn= oci_connect($dbusername,$dbpassword,$database);
$result = oci_parse($conn, 'SELECT branch,tracks,location,start_time,stop_time FROM tte_track_work where t_page = (SELECT MAX(id) from track_page)');
oci_execute($result);

while($row = oci_fetch_array($result,OCI_ASSOC+OCI_RETURN_NULLS))
{

//ok so the foreach will retun all the values in the database with index [0]. I do not want this I want column indexes so that I can update individual cells.

foreach($row as $item => $value)
{

print_r($value);
// what I need is for each column to have incrementing indexes so that the value tag in the form has right value and will update the correct information
}

print_r($result);
// Ok so say I have three rows of data returned. I need branch to be [0]>data, [1]>data [2]>data so that when I say $value[$i] I can update an individual cell. This way I can post branch[] and then I can update $value[$i] for the cells that were modified in the form and make the change in the database.
echo '<input type="text" name="branch[]" value="'.$value[$i].'"/>';
echo'<input type="text" name="tracks[]" value"'.$value[$i].'"/>';


echo'
<input type="submit" name="submit" value="Update"/>
</table>
</form>';

?>

Re: Help updating single value of returned database rows.

Posted: Wed Apr 14, 2010 1:08 pm
by JakeJ
You don't need a for each loop inside your while loop.

Code: Select all

While ($row = while($row = oci_fetch_array($result,OCI_ASSOC+OCI_RETURN_NULLS))
{
echo $row['branch']; //substitute 'branch' for your other field names and you get the idea.
}