473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Getting Records to update when dropdown list is changed

Hello

In a php file I have a drop down list with index numbers in whos default
value is feed into an sql query that filters records from my database and
displays them in an html table. Trouble is this happens as soon as the php
is run so bringing up the same records filtered from the default index. Also
when I select a new index no from the drop down list is doesnt refilter the
records bringing up the ones for the new list. It still shows the old
default ones and the dropdown list changes back to the default value. What
alterations do I need to make?
Some of my code below (Ive taken irrelevent bits out and simplified the SQL
Statements to show only the important bits)

Also I dont want to display the index no in the dropdown box. I wish to
display its accociated description and only use the index for filtering. How
do I acheive this?

<?php

$query_NC = "SELECT NCIndex, TopicDesc FROM NC WHERE StatusID = 1 ORDER BY
TopicDesc ASC";
$NC = mysql_query($query_NC, $conn) or die(mysql_error());
$row_NC = mysql_fetch_assoc($NC);
$totalRows_NC = mysql_num_rows($NC);
?>
<html>
<head>
</head>

<body>

</p>
<p>Use the drop down lists to filter the database:</p>
<blockquote>
<form name="form2" method="post" action="<?php echo
$_SERVER['PHP_SELF']?>">
<p>
<select name="select">
<?php
do {
?>
<option value="<?php echo $row_NC['NCIndex']?>"<?php if
(!(strcmp($row_NC['NCIndex'], $row_NC['NCIndex']))) {echo "SELECTED";}
?>><?php echo $row_NC['NCIndex']?></option>
<?php
} while ($row_NC = mysql_fetch_assoc($NC));
$rows = mysql_num_rows($NC);
if($rows > 0) {
mysql_data_seek($NC, 0);
$row_NC = mysql_fetch_assoc($NC);
}
?>
</select>
</p>
<p>
<input type="submit" name="Submit2" value="Submit">
</p>
</form>
<p>
<form name="form3" method=post action="">
<p>
<?php
// Request the text of all the Questions
$result = mysql_query("SELECT Mystuff FROM MyTables WHERE Questions.TypeID =
QuestionType.TypeID AND NCIndex= '".$row_NC['NCIndex']."' ORDER BY
QuestionNo");
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
$row = mysql_fetch_assoc($result);
extract($row);
?>
<input type="submit" name="Submit" value="Submit">
</p>
<table width="983" border="2" align="left" cellpadding="0"
cellspacing="0">
<tr>
<td width="50"><div align="left"><span
class="style2">Select</span></div></td>
<td width="89"><span class="style2">Question No </span></td>
<td width="247"><span class="style2">Question</span></td>
<td width="118"><span class="style2">Type</span></td>
<td width="282">Options</td>
<td width="181"><span class="style2">Image</span></td>
</tr>
<tr>
<?php
while($row =& mysql_fetch_assoc($result)) {
extract($row);

?>
<tr class="<?php echo $class; ?>">
<td width="50" rowspan="5" valign="top">
<div align="center">
<input type="checkbox" name="checkbox[]" value="<? echo
$QuestionNo?>"

</div></td>
<td width="89" rowspan="5" valign="top"><?php echo $QuestionNo;
?>&nbsp;</td>
<td width="247" rowspan="5" valign="top"><?php echo $Question;
?></td>
<td width="118" rowspan="5" valign="top"><div
align="center"></div>
<?php echo $TypeDesc; ?></td>
<td width="282" valign="top"><div align="left"></div>
<?php echo $Optiona; ?></td>
<tr class="<?php echo $class; ?>">
<td width="282" valign="top"><?php echo $Optionb; ?></td>
</tr>
<tr class="<?php echo $class; ?>">
<td width="282" valign="top"><?php echo $Optionc; ?></td>
</tr>
<tr class="<?php echo $class; ?>">
<td width="282" valign="top"><?php echo $Optiond; ?></td>
</tr>
<tr class="<?php echo $class; ?>">
<td width="282" height="20" valign="top"><?php echo $Optione;
?></td>
</tr>
<?php
} // end while
?>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>
<p></blockquote>
</body>
<html>
Oct 20 '05 #1
1 10155
Ian Davies wrote:
Hello

In a php file I have a drop down list with index numbers in whos default
value is feed into an sql query that filters records from my database and
displays them in an html table. Trouble is this happens as soon as the php
is run so bringing up the same records filtered from the default index. Also
when I select a new index no from the drop down list is doesnt refilter the
records bringing up the ones for the new list. It still shows the old
default ones and the dropdown list changes back to the default value. What
alterations do I need to make?
Some of my code below (Ive taken irrelevent bits out and simplified the SQL
Statements to show only the important bits)

Also I dont want to display the index no in the dropdown box. I wish to
display its accociated description and only use the index for filtering. How
do I acheive this?

<?php

$query_NC = "SELECT NCIndex, TopicDesc FROM NC WHERE StatusID = 1 ORDER BY
TopicDesc ASC";
$NC = mysql_query($query_NC, $conn) or die(mysql_error());
$row_NC = mysql_fetch_assoc($NC);
$totalRows_NC = mysql_num_rows($NC);
?>
<html>
<head>
</head>

<body>

</p>
<p>Use the drop down lists to filter the database:</p>
<blockquote>
<form name="form2" method="post" action="<?php echo
$_SERVER['PHP_SELF']?>">
<p>
<select name="select">
<?php
do {
?>
<option value="<?php echo $row_NC['NCIndex']?>"<?php if
(!(strcmp($row_NC['NCIndex'], $row_NC['NCIndex']))) {echo "SELECTED";}
?>><?php echo $row_NC['NCIndex']?></option>
<?php
} while ($row_NC = mysql_fetch_assoc($NC));
$rows = mysql_num_rows($NC);
if($rows > 0) {
mysql_data_seek($NC, 0);
$row_NC = mysql_fetch_assoc($NC);
}
?>
</select>
</p>
<p>
<input type="submit" name="Submit2" value="Submit">
</p>
</form>
<p>
<form name="form3" method=post action="">
<p>
<?php
// Request the text of all the Questions
$result = mysql_query("SELECT Mystuff FROM MyTables WHERE Questions.TypeID =
QuestionType.TypeID AND NCIndex= '".$row_NC['NCIndex']."' ORDER BY
QuestionNo");
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
$row = mysql_fetch_assoc($result);
extract($row);
?>
<input type="submit" name="Submit" value="Submit">
</p>
<table width="983" border="2" align="left" cellpadding="0"
cellspacing="0">
<tr>
<td width="50"><div align="left"><span
class="style2">Select</span></div></td>
<td width="89"><span class="style2">Question No </span></td>
<td width="247"><span class="style2">Question</span></td>
<td width="118"><span class="style2">Type</span></td>
<td width="282">Options</td>
<td width="181"><span class="style2">Image</span></td>
</tr>
<tr>
<?php
while($row =& mysql_fetch_assoc($result)) {
extract($row);

?>
<tr class="<?php echo $class; ?>">
<td width="50" rowspan="5" valign="top">
<div align="center">
<input type="checkbox" name="checkbox[]" value="<? echo
$QuestionNo?>"

</div></td>
<td width="89" rowspan="5" valign="top"><?php echo $QuestionNo;
?>&nbsp;</td>
<td width="247" rowspan="5" valign="top"><?php echo $Question;
?></td>
<td width="118" rowspan="5" valign="top"><div
align="center"></div>
<?php echo $TypeDesc; ?></td>
<td width="282" valign="top"><div align="left"></div>
<?php echo $Optiona; ?></td>
<tr class="<?php echo $class; ?>">
<td width="282" valign="top"><?php echo $Optionb; ?></td>
</tr>
<tr class="<?php echo $class; ?>">
<td width="282" valign="top"><?php echo $Optionc; ?></td>
</tr>
<tr class="<?php echo $class; ?>">
<td width="282" valign="top"><?php echo $Optiond; ?></td>
</tr>
<tr class="<?php echo $class; ?>">
<td width="282" height="20" valign="top"><?php echo $Optione;
?></td>
</tr>
<?php
} // end while
?>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>
<p></blockquote>
</body>
<html>


Without putting the code on a php server it's a bit difficult to be certain
but I think what you need is an if(isset($select.... Then feed that into
your sql query and it should work. Below is a cut down exmaple from
something I did for a friend a while ago. Hopefully it will make it a
little clearer what I mean

<form method="post" action="seasons.php">

<table width="20%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="60%">Choose Season</td>
<td width="40%"><div align="right">
<select name="season">
<option> </option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
</td>
</tr>
</table>

<input type="submit" value="Go">&nbsp;&nbsp;<input type="reset" value="Clear">
</form>
<?
include ('connect.php');
if(isset($season))
{
$sql="SELECT * from sgate WHERE season like '$season' ORDER BY episode";
$result=mysql_query("$sql");

print '<b>Season :- '.$season."</b>";
print"<div align='center'>";
print"<table border='1' width='60%'>";

while($row=mysql_fetch_array($result))
{
print "<tr><td>".$row[episode]."</td><td>".$row[air_date]."</td><td><a
href='edit.php?id=".$row[id]."'>Edit</a></td></tr>";
print "<tr><td colspan='2'><b>".$row[title]."</b></td><td>&nbsp;</td></tr>";
print "<tr><td colspan='3'><font
size='-1'>".$row[synopsis]."</font></td></tr>";
print "<tr><td colspan='3'><hr></td></tr>";
}
}
?>
--
Regards

Neil

Registered Linux User 324599
Oct 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Reply via newsgroup | last post by:
Folks, When performing an update in mysql (using PHP), can I find out how many records were matched? mysql_affected_rows() won't work... and I have the following problem that I thought I...
15
by: Philip Mette | last post by:
I am begginner at best so I hope someone that is better can help. I have a stored procedure that updates a view that I wrote using 2 cursors.(Kind of a Inner Loop) I wrote it this way Because I...
3
by: DD | last post by:
I have a mainform with a subform. > The main form has a dropdown box "chooseMonth", in the afterupdate event > i requery the subform so all records with the same date are viewed. > Now i only want...
8
by: k | last post by:
Hi all I split a database in a table-part and a all-the-rest-part and linked the tables, but my code adding records to a table crashes on Set rs = db.OpenRecordset("tblDeltakelse",...
2
by: hypomite | last post by:
I have an handler for the SelectedIndexChanged event of a dropdown box. I have also set the AutoPostBack option to True. When you select any item besides the first one, the event sucessfully fires....
6
by: Mark | last post by:
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy. ...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
21
by: rfdjr1 | last post by:
I'm using Access 2000. I have a raher simple database of my CD collection, with just three fields, Artist, Album Title and Type of Music. While going to update it today with a couple new CD's, I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.