Here's a test page:
http://www.menc-eastern.org/test.php
You see 5 records.
Now "query" the database:
http://www.menc-eastern.org/test.php?instrument=Winds-Flute
Just two records, both instruemnts are flutes... so far, so good.
Now click on one of the hyperlinked "ranks"... change the rank number and Update the value.
It displays "Student was successfully updated!"... and it goes back to the URL I wanted
http://www.menc-eastern.org/test.php?instrument=Winds-Flute
... but there is only one student listed there (the one that was just updated). Copy and paste the EXACT same URL in a new browser window, and it displays both students.
It's probably doing that by design, but I really want to change it. How do I make it display all (in this case, both) students, immediately after the update?
here's my code:
<? $foobar = getenv('HTTP_REFERER'); ?>
<?
if (isset($_POST['updatestudentbt']))
{
if ($_POST['rank'] != '')
{
if (mysql_query("UPDATE bocj SET `rank` = '".$_POST['rank']."' WHERE `id`= '".$_POST['id']."'"))
echo "Student was successfully updated!<br /><br />";
else
echo "Student was NOT updated!<br /><br />";
}
}
if ($_GET['a'] == "edit")
{
$sql = "SELECT * FROM bocj WHERE id='".$_GET['id']."'";
$result = mysql_query($sql);
$data = mysql_fetch_array($result);
?>
<form action="<? echo $foobar?>" method="post" name="editstudent">
<b>Name</b>: <? echo $data['student']?>
<br />
<b>Instrument</b>: <?=$data['instrument']?>
<br />
<br />
<b>Rank</b>: <input name="rank" type="text" id="rank" size="7" value="<? echo $data['rank']?>" onfocus="if(this.value=='rank?') {this.value='';}" onblur="if(this.value=='rank?') {this.value='';}" />
<br />
<br />
<input type="hidden" name="id" value="<? echo $data['id']?>" />
<input type="submit" value="Update" name="updatestudentbt" />
</p>
</form>
<br />
<?
}
else
{
?>
<?
function pparams($sort) {
global $sponsor, $school, $student, $instrument;
echo $HTTP_SERVER_VARS['PHP_SELF'];
echo "?sponsor=".htmlentities(urlencode($sponsor));
echo "&student=".htmlentities(urlencode($student));
echo "&instrument=".htmlentities(urlencode($instrument));
echo "&sort=".htmlentities(urlencode($sort));
}
if (!$sort) $sort="instrument";
?>
<table>
<tr>
<td><strong><a href="<? pparams("sponsor"); ?>">Sponsor</a></strong></td>
<td><strong><a href="<? pparams("student"); ?>">Student</a></strong></td>
<td><strong><a href="<? pparams("instrument"); ?>">Instrument</a></strong></td></td>
<td><strong><a href="<? pparams("rank"); ?>">Rank</a></strong></td>
<td><strong>Comments</strong></td>
</tr>
<?
$sql = "SELECT bocj.sponsor,bocj.student,bocj.instrument,bocj.rank,bocj.id,bocj.comments
FROM bocj
WHERE ((bocj.sponsor LIKE '$sponsor%')
and (bocj.student LIKE '$student%')
and (bocj.instrument LIKE '$instrument%')
and (bocj.rank LIKE '$rank%')
and (bocj.id LIKE '$id%')
and (bocj.comments LIKE '$comments%'))
ORDER BY bocj.$sort";
$result = mysql_query($sql);
while ($data = mysql_fetch_array($result))
{
?>
<tr>
<td><?=$data['sponsor']?></td>
<td><?=$data['student']?></td>
<td><?=$data['instrument']?></td>
<td><a href="test.php?p=index&a=edit&id=<?=$data['id']?>"><?=$data['rank']?></a></td>
<td width="120"><?=$data['comments']?></td>
</tr>
<?}?>
</table>
<? } ?>
Thanks for reading.
~Wayne