473,545 Members | 1,224 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($qu ery_NC, $conn) or die(mysql_error ());
$row_NC = mysql_fetch_ass oc($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_ass oc($NC));
$rows = mysql_num_rows( $NC);
if($rows > 0) {
mysql_data_seek ($NC, 0);
$row_NC = mysql_fetch_ass oc($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("SE LECT Mystuff FROM MyTables WHERE Questions.TypeI D =
QuestionType.Ty peID AND NCIndex= '".$row_NC['NCIndex']."' ORDER BY
QuestionNo");
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
$row = mysql_fetch_ass oc($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"><s pan
class="style2"> Select</span></div></td>
<td width="89"><spa n class="style2"> Question No </span></td>
<td width="247"><sp an class="style2"> Question</span></td>
<td width="118"><sp an class="style2"> Type</span></td>
<td width="282">Opt ions</td>
<td width="181"><sp an class="style2"> Image</span></td>
</tr>
<tr>
<?php
while($row =& mysql_fetch_ass oc($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"><d iv
align="center"> </div>
<?php echo $TypeDesc; ?></td>
<td width="282" valign="top"><d iv 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 10166
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($qu ery_NC, $conn) or die(mysql_error ());
$row_NC = mysql_fetch_ass oc($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_ass oc($NC));
$rows = mysql_num_rows( $NC);
if($rows > 0) {
mysql_data_seek ($NC, 0);
$row_NC = mysql_fetch_ass oc($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("SE LECT Mystuff FROM MyTables WHERE Questions.TypeI D =
QuestionType.Ty peID AND NCIndex= '".$row_NC['NCIndex']."' ORDER BY
QuestionNo");
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
$row = mysql_fetch_ass oc($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"><s pan
class="style2"> Select</span></div></td>
<td width="89"><spa n class="style2"> Question No </span></td>
<td width="247"><sp an class="style2"> Question</span></td>
<td width="118"><sp an class="style2"> Type</span></td>
<td width="282">Opt ions</td>
<td width="181"><sp an class="style2"> Image</span></td>
</tr>
<tr>
<?php
while($row =& mysql_fetch_ass oc($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"><d iv
align="center"> </div>
<?php echo $TypeDesc; ?></td>
<td width="282" valign="top"><d iv 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($selec t.... 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%">Cho ose Season</td>
<td width="40%"><di v 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">&nbs p;&nbsp;<input type="reset" value="Clear">
</form>
<?
include ('connect.php') ;
if(isset($seaso n))
{
$sql="SELECT * from sgate WHERE season like '$season' ORDER BY episode";
$result=mysql_q uery("$sql");

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

while($row=mysq l_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'><fo nt
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
3830
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 could resolve with a simple function: Example: I have 50records - I want to update a selection of the recods - some,
15
3804
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 couldn't do it using reqular transact SQL. The problem is that this procedure is taking longer and longer to run. Up to 5 hours now! It is...
3
2652
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 to print the selected records of the selected month > Can any one advise on the below Below is code i am trying to adapt (Thanks Don) 1.This...
8
2079
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", dbOpenTable, dbAppendOnly) I think, some places where I do the same thing to another table it just says "Invalid Operation", I press OK and nothing happens,...
2
3223
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. However, if you ever (even after you have selected other options previously) select the first option in the dropdown, the AutoPostBack fires(the...
6
10660
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. Let's say you select 1 of the items, and are properly redirected. You press the back button. I have three servers providing two different...
11
2231
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 reflect that the 3 items have been deleted only to discover that the 3 items appear, however when I click on them to display their information which...
16
3464
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 in a hidden field) I wish the user to be able to edit the data in the table, so I have extracted the records into hiddenfield, textareas, dropdown...
21
1883
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 noticed that if I sort alphabetically by Artist it have 387 records but if I sort by Album Title it shows 393 records. Any idea why this would be? ...
0
7398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7752
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1878
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
701
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.