473,386 Members | 1,815 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,386 software developers and data experts.

Dropdown list - Trying to get default populated from db.

Oli
Nooby question but when I try and get this to work (it should identify which
rows in the database have GK, MID, DEF, FWD against them and then put
SELECTED into the option value to give a default of what the entry is
currently) it just adds SELECTED to all the results as if $row["Position"]
is returning true against all four conditions? What am I doing wrong?

Thanks,

O.

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo("<td>" . $row["Surname"] . "</td>");
echo("<td>" . $row["TeamName"] . "</td>");
?>
<td><select name="select2">
<option value="GK"<? if ($row["Position"] = "GK") {?>SELECTED<?}
?>>GK</option>
<option value="DEF"<? if ($row["Position"] = "DEF") {?>SELECTED<?}
?>>DEF</option>
<option value="MID"<? if ($row["Position"] = "MID") {?>SELECTED<?}
?>>MID</option>
<option value="FWD"<? if ($row["Position"] = "FWD") {?>SELECTED<?}
?>>FWD</option>
?>>
</select></td>
<?

echo("<td>" . $row["Selected"] . "</td>");
}
Jul 17 '05 #1
5 2044
Oli wrote:
<td><select name="select2">
<option value="GK"<? if ($row["Position"] = "GK") {?>SELECTED<?}
?>>GK</option>
<option value="DEF"<? if ($row["Position"] = "DEF") {?>SELECTED<?}
?>>DEF</option>
<option value="MID"<? if ($row["Position"] = "MID") {?>SELECTED<?}
?>>MID</option>
<option value="FWD"<? if ($row["Position"] = "FWD") {?>SELECTED<?}
?>>FWD</option>
?>>
</select></td>
<?

echo("<td>" . $row["Selected"] . "</td>");
}


You have to use == instead of =. = means assignment, so you actually
assign GD, DEF, ... to $row['Position'], which returns true since it
worked. If you'd use if ( $row['Position'] == '...' ) your script should
work.

--
Pieter Nobels
Jul 17 '05 #2
Oli
You beauty!! :D

O.

"Pieter Nobes" <pi******@MOVE.opengate.be> wrote in message
news:1L***********************@phobos.telenet-ops.be...

You have to use == instead of =. = means assignment, so you actually
assign GD, DEF, ... to $row['Position'], which returns true since it
worked. If you'd use if ( $row['Position'] == '...' ) your script should
work.

--
Pieter Nobels

Jul 17 '05 #3
Oli
Next question I guess is how do I get this huge table to pass its variables
back to the database after a submit is um..submitted..

From what I have read, normally I would use the POST method and that would
pass the variables and then I could put them back in the database but as all
of these variables have the same names, how best to do it?

O.

"Oli" <ov**********@mail.com> wrote in message
news:cg**********@titan.btinternet.com...
You beauty!! :D

O.

Jul 17 '05 #4
In article <cg**********@hercules.btinternet.com>, Oli wrote:
Next question I guess is how do I get this huge table to pass its variables
back to the database after a submit is um..submitted..

From what I have read, normally I would use the POST method and that would
pass the variables and then I could put them back in the database but as all
of these variables have the same names, how best to do it?

<?php
if (isset($_POST['submit']))
{
echo "SELECTED VALUES: ";
while (list ($key, $val) = each ($_POST['multiselect']))
{
echo "$val ";
}
echo "<br>\n";
}
?>

<form method="post">
<select name="multiselect[]" multiple>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="submit" value="submit" name="submit" />
</form>

--
Tim Van Wassenhove <http://home.mysth.be/~timvw>
Jul 17 '05 #5

"Oli" <ov**********@mail.com> wrote in message
news:cg**********@hercules.btinternet.com...
Next question I guess is how do I get this huge table to pass its
variables
back to the database after a submit is um..submitted..

From what I have read, normally I would use the POST method and that would
pass the variables and then I could put them back in the database but as
all
of these variables have the same names, how best to do it?


If you construct your HTML document using data from multiple database rows
then you will have duplicate field names. The way around this is to index
each fieldname by row number, as in field[$row].

When the form is posted back PHP will present you the data in the format:

fieldname: array =
0: string = value
1: string = value
2: string = value

You simply step through this like any other array. Easy when you know how.

HTH.

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #6

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

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
1
by: jzhang29 | last post by:
I have a JSP page and it contains a dropdown list called Office. What I try to do is: When I select different office from this list, the information of office (address, phone,etc) will be...
0
by: E . | last post by:
I seem to be getting nowhere with this problem here is the situation. I have a webform with a data grid populated with the results of a table that has only 3 fields. Then below that are 1...
0
by: Henke | last post by:
Hi, I have done some research about my problem I have when using the "back button" in IE to go back to a page with two dropdown lists. The both dropdown lists are populated with data. The...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
3
by: er1 | last post by:
Hi all, I have created a double dropdown list. Based on the first list selection, second list populates (this works fine). I have a submit button, which when clicked should run a select query...
3
by: =?Utf-8?B?SmF2YW1hbjU5?= | last post by:
I have an ASP.NET example which programmatically builds a drop down list. public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.DropDownList ddlCategories; public...
11
by: eureka | last post by:
Hi All, I'm training in Servlets, JSP and JavaScript, I have a web page in which there's a "StudentName" textbox and below it is a "Names" Dropdown list. Initially the Textbox is empty and...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.