<select> problem

Hi,
I fetched All Roll Numbers in from Students table. I fire an event on Submit to read Roll Number from and display students information according to it. But it is not displaying the selected number in . Please help me.

Thanks

Can’t help you without seeing the code you’re working with first.

Hi, I am a author of the question. and below is the code
[php]

<?php $con=mysql_connect("localhost","root",""); mysql_select_db("ashwathDB",$con); $selectEnqId = mysql_query("select * from Students"); echo ""; echo "Select the ID : "; $rNo = $_GET['RollNO']; while($row=mysql_fetch_array($selectEnqId)) { echo "$row[0]"; } echo " "; $b = $_GET['btn1']; if($b) { echo $rNo; //to display accepted roll number }//end of If echo ""; ?>[/php]

Above code is working fine for me… but unable to display the selected / passed ROll Number in .

thanks

You’re missing a few key bits of code in there, this is what it should be
[php]

<?php $con=mysql_connect("localhost","root",""); mysql_select_db("ashwathDB",$con); if(isset($_POST['btn1'])) { // name of your submit button $b = $_POST['RollNO']; } $selectEnqId = mysql_query("SELECT * FROM Students ORDER BY id DESC"); echo ""; echo "Select the ID : "; while($row=mysql_fetch_array($selectEnqId)) { echo "$row[id]"; } echo ""; if($b) { //echo $rNo; //to display accepted roll number echo $b //$rNo doesn't exist anywhere yet, can't echo it. } ?>[/php]

$b wasn’t equalling anything because the option didn’t have an assigned value. Change id to whatever is supposed be selected in that box.

Hey thanks for answer.

But using your code the selected number is displaying on the browser. I don’t want to display it.

If there are 4 numbers are available 1,2,3,4 and if I select suppose 2 from tag then after clicking on the button 2 value should display in as a selected value. Right now it is displaying first value.

That’s where your code is displaying it. All i did was organize and fix what you put up there. So you want it to remember the selection after the submit button is pressed? simple enough
[php]while($row=mysql_fetch_array($selectEnqId)) {
if(isset($_POST[‘btn1’])) {
echo “$row[id]”;
} else {
echo “$row[id]”;
}
}[/php]
Not sure if that’ll work or not, that’s not how i usually do it, but give it a try.

I wrote below code :

while($row=mysql_fetch_array($selectEnqId)) {
if(isset($_POST[‘btn1’])) {
echo "<option value=’$row[0]’

checked=‘checked’>$row[0]";
} else {
echo “$row[0]”;
}
}

Here, if I write $row[id] then it is now displaying any Numbers in that’s I mentioned the index of the column. But still it is not selecting in the . Is it working on your machine?

I had the wrong attribute in there, change checked=‘checked’ to selected=‘selected’

but fyi, its easier to use array since you can specify column names. index numbers can change depending on how information is exchanged, column names won’t change.

No… still not working…
I also wrote your logic in my another code [which is same] on different table… but still it is not displaying

here is the complete code:

<?php $con=mysql_connect("localhost","root",""); mysql_select_db("ashwathDB",$con); if(isset($_POST['btn1'])) { // name of your submit button $b = $_POST['EnqId']; echo $b; } //echo $_POST['btn1']; $selectEnqId = mysql_query("SELECT * FROM Enquiry ORDER BY Enqid DESC"); echo ""; echo "Select the ID : "; while($row=mysql_fetch_array($selectEnqId)) { if(isset($_POST['btn1'])) { echo "$row[0]"; } else { echo "$row[0]"; } } echo ""; ?>

ok, here’s how i normally do it[php]
$qry = mysql_query(“SELECT * FROM enquiry”);

$dis = “”;
while($row = mysql_fetch_array($qry)) {
if($row[‘EnqId’] == $_POST[‘rollno’]) {
$dis .= “$row[EnqId]”;
} else {
$dis .= “$row[EnqId]”;
}
}
$dis = “”;

// where ever you want to display the select box
echo $dis;
// or if you’re doing it outside of regular php tags

<?=$dis?>[/php]

That will display

1 2 3 4

I worked lot on the code… but still unable to execute. Please import my database into your PC and run the code and tell me weather the number is select or not.

thanks

Ok, ill import it and test the code in your last post

Sponsor our Newsletter | Privacy Policy | Terms of Service