473,402 Members | 2,055 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,402 software developers and data experts.

Populate table at selection



I have a combo box (select) and when the user selects a value I want to
populate an HTML table from DB depending on the value selected. Whats the
easiest way to achieve it. I've searched google and the examples require
java script. Is there a way to do this with only PHP. I had the impression
you could do anything with PHP. Infact there is a book titled 'How to do
every thing in PHP'!
--
When you argue with a fool, chances are he's doing the same
Jun 2 '08 #1
8 1806
freelance71 wrote:
I have a combo box (select) and when the user selects a value I want to
populate an HTML table from DB depending on the value selected. Whats the
easiest way to achieve it. I've searched google and the examples require
java script. Is there a way to do this with only PHP. I had the impression
you could do anything with PHP. Infact there is a book titled 'How to do
every thing in PHP'!
--
When you argue with a fool, chances are he's doing the same
PHP is server side. A select box is client side. You need a client
side routine - i.e. javascript.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #2

"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:m5******************************@comcast.com. ..
freelance71 wrote:
>I have a combo box (select) and when the user selects a value I want to
populate an HTML table from DB depending on the value selected. Whats the
easiest way to achieve it. I've searched google and the examples require
java script. Is there a way to do this with only PHP. I had the
impression you could do anything with PHP. Infact there is a book titled
'How to do every thing in PHP'!
--
When you argue with a fool, chances are he's doing the same

PHP is server side. A select box is client side. You need a client side
routine - i.e. javascript.

--
Thanks.
Can a PHP script access/get the default value of a Combo box when the page
loads?
Jun 2 '08 #3
On Tue, 22 Apr 2008 11:08:06 +0500, in comp.lang.php "freelance71"
<f9******@yahoo.com>
<fu**********@registered.motzarella.orgwrote:
>|
| "Jerry Stuckle" <js*******@attglobal.netwrote in message
| news:m5******************************@comcast.com. ..
| freelance71 wrote:
| >I have a combo box (select) and when the user selects a value I want to
| >populate an HTML table from DB depending on the value selected. Whats the
| >easiest way to achieve it. I've searched google and the examples require
| >java script. Is there a way to do this with only PHP. I had the
| >impression you could do anything with PHP. Infact there is a book titled
| >'How to do every thing in PHP'!
| >--
| >When you argue with a fool, chances are he's doing the same
| >
| PHP is server side. A select box is client side. You need a client side
| routine - i.e. javascript.
| >
| --
|
| Thanks.
| Can a PHP script access/get the default value of a Combo box when the page
| loads?
If the default value is obtained from a database and php sets the
value then yes.

If the default value is within the HTML page then you will need to
parse the page (within php) to get the value. This needs to be done
before the page is sent to the browser.

Why don't you want to use javascript as what you've described is an
ideal candidate for AJAX.
-- -------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
-- -------------------------------------------------------------
Jun 2 '08 #4
freelance71 wrote:
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:m5******************************@comcast.com. ..
>freelance71 wrote:
>>I have a combo box (select) and when the user selects a value I want to
populate an HTML table from DB depending on the value selected. Whats the
easiest way to achieve it. I've searched google and the examples require
java script. Is there a way to do this with only PHP. I had the
impression you could do anything with PHP. Infact there is a book titled
'How to do every thing in PHP'!
--
When you argue with a fool, chances are he's doing the same
PHP is server side. A select box is client side. You need a client side
routine - i.e. javascript.

--

Thanks.
Can a PHP script access/get the default value of a Combo box when the page
loads?
If PHP is setting the value in the combobox, yes.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #5
On Apr 22, 7:23 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
freelance71 wrote:
"Jerry Stuckle" <jstuck...@attglobal.netwrote in message
news:m5******************************@comcast.com. ..
freelance71 wrote:
I have a combo box (select) and when the user selects a value I want to
populate an HTML table from DB depending on the value selected. Whats the
easiest way to achieve it.
You can do it all with PHP if you'd like, although it might get
messy .
You've got 3 ways to go:
1) The Wrong Way.
Bake everything into the file using php. This means creating the
select form with php, and also dynamically creating javascript with
php. Because you already know the only possibly options the user might
select, you just load the different table data though php/mysql and
shove them into javascript variables (within php. i.e. <?php echo
"<script type=\text/javascript\"";.....) You will be heading down the
rabbit hole this way.

2) The Old Way:
Create the form with HTML. Set the form action to a PHP page (It can
even be the same page that displays the form)
The form sends a GET request to the PHP Page, you take the value the
user has chosen with $userchoice=$_GET['userchoice']; Work your magic
with mysql, and create a table with the data and display the data with
a inline php variable.

3) The Right Way:
Use Ajax:
Create a div specifically for the table
Set one of the SELECT events to a custom javascript handler.
something like <inputtype = "select" id="myselect"
onmouseup="javascript:myHandler(this.form);"
then u make a javascript function
function myHandler(form)
{
myselect = form.select.value;
}
Then you use your favorite Ajax framework to send the value to the
server (via ajax) you will need to write a custom callback handler for
the data that comes back from php.
function callBackAjaxHandler(response)
{
document.getElementById('mytablediv').innerHTML = response;
}
Jun 2 '08 #6
On Tue, 22 Apr 2008 10:11:31 -0700 (PDT), venti wrote:
On Apr 22, 7:23 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>freelance71 wrote:
"Jerry Stuckle" <jstuck...@attglobal.netwrote in message
news:m5******************************@comcast.com ...
freelance71 wrote:
I have a combo box (select) and when the user selects a value I want to
populate an HTML table from DB depending on the value selected. Whats the
easiest way to achieve it.

You can do it all with PHP if you'd like, although it might get
messy .
You've got 3 ways to go:
1) The Wrong Way.
Bake everything into the file using php. This means creating the
select form with php, and also dynamically creating javascript with
php. Because you already know the only possibly options the user might
select, you just load the different table data though php/mysql and
shove them into javascript variables (within php. i.e. <?php echo
"<script type=\text/javascript\"";.....) You will be heading down the
rabbit hole this way.

2) The Old Way:
Create the form with HTML. Set the form action to a PHP page (It can
even be the same page that displays the form)
The form sends a GET request to the PHP Page, you take the value the
user has chosen with $userchoice=$_GET['userchoice']; Work your magic
with mysql, and create a table with the data and display the data with
a inline php variable.

3) The Right Way:
Use Ajax:
Create a div specifically for the table
Set one of the SELECT events to a custom javascript handler.
something like <inputtype = "select" id="myselect"
onmouseup="javascript:myHandler(this.form);"
then u make a javascript function
function myHandler(form)
{
myselect = form.select.value;
}
Then you use your favorite Ajax framework to send the value to the
server (via ajax) you will need to write a custom callback handler for
the data that comes back from php.
function callBackAjaxHandler(response)
{
document.getElementById('mytablediv').innerHTML = response;
}
#3 looks a lot messier than #2. Never trust the client.

--
Mares eat oats, and does eat oats, and little lambs eat ivy,
A kid will eat ivy too, wouldn't you?
Jun 2 '08 #7
#3 looks a lot messier than #2. Never trust the client.
Well, 3 requires more code up front, but it saves you having full
round trips with a page refresh. The payoff for Ajax is that the
headers remain the same, and only the div containing the table is
changed through the DOM.
As for trusting the client, of course, don't. This means, among other
things, client and (more important) server-side parsing for sql
injection. But ultimately I don't see any real difference in client
based attacks one way or the other.
Jun 2 '08 #8
Peter H. Coffin wrote:
On Tue, 22 Apr 2008 10:11:31 -0700 (PDT), venti wrote:
>On Apr 22, 7:23 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>>freelance71 wrote:

"Jerry Stuckle" <jstuck...@attglobal.netwrote in message
news:m5******************************@comcast.c om...

freelance71 wrote:
>
>I have a combo box (select) and when the user selects a value I want to
>populate an HTML table from DB depending on the value selected. Whats the
>easiest way to achieve it.
>>
You can do it all with PHP if you'd like, although it might get
messy .
You've got 3 ways to go:
1) The Wrong Way.
Bake everything into the file using php. This means creating the
select form with php, and also dynamically creating javascript with
php. Because you already know the only possibly options the user might
select, you just load the different table data though php/mysql and
shove them into javascript variables (within php. i.e. <?php echo
"<script type=\text/javascript\"";.....) You will be heading down the
rabbit hole this way.

2) The Old Way:
Create the form with HTML. Set the form action to a PHP page (It can
even be the same page that displays the form)
The form sends a GET request to the PHP Page, you take the value the
user has chosen with $userchoice=$_GET['userchoice']; Work your magic
with mysql, and create a table with the data and display the data with
a inline php variable.

3) The Right Way:
Use Ajax:
Create a div specifically for the table
Set one of the SELECT events to a custom javascript handler.
something like <inputtype = "select" id="myselect"
onmouseup="javascript:myHandler(this.form);"
then u make a javascript function
function myHandler(form)
{
myselect = form.select.value;
}
Then you use your favorite Ajax framework to send the value to the
server (via ajax) you will need to write a custom callback handler for
the data that comes back from php.
function callBackAjaxHandler(response)
{
document.getElementById('mytablediv').innerHTML = response;
}

#3 looks a lot messier than #2. Never trust the client.

You can always make the Javascript fire from an event on a hyperlink
that would reload the entire page and accomplish the same thing for
those who do not have JS enabled.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Nothing he's got he really needs
Twenty first century schizoid man.
***********************************

Jun 2 '08 #9

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

Similar topics

1
by: Cindi | last post by:
Hi, Another newbie with a question that I hope someone can point me in the right direction. The goal is to populate a text box with data according to the selection in a combo box while still...
14
by: Barney | last post by:
How can I populate a textbox from a dataview? I have a dataset i'm filtering on and i want to populate several textboxes based on that filter. How can i get that to work? I've tried: ...
0
by: ROO | last post by:
Hi Everyone, I have a database table that have 4 field( C1, C2, M1, M2) on my form i have two combo box ComboC and ComboM C1 C2 M1 M2 1 ...
0
by: SimpDogg | last post by:
Hey guys another Newbie here... I have a combobox(JobName) on my form tied to a table named (Jobs) with one field for all of the jobs in the comboxbox. I want to auto populate the Due Out Date...
1
by: girjer | last post by:
I want to populate two table fields on a selection of either combo box, list box or any option button. For e.g. When I select 'YES' as an option I want to populate two fields in the table i.e....
1
by: KMEscherich | last post by:
Using Access '97 Hi there, am wondering if someone can please help me with the following: I have a master table (T_INVESTIGATION) that contains the following fields as well as other fields. ...
4
by: whamo | last post by:
I have the need to populate a field based on the selection in a combo box. Starting out simple. (2) tables tbl_OSE_Info and tbl_Input; tbl_OSE_Info has three fields: Key, OSE_Name and OSE_Wt...
5
by: giandeo | last post by:
Hello Experts. Could you find a solution for this problem please! I have the following tables in Access Database Table Name: origin Fields Names: country, countrycode Table Name: make...
2
by: Ronald | last post by:
I hope somebody can help. I can't get into the specifics of my project, but I'll try to create a simple example: tblVehicle * VIN (text box) * Make (text box) * Model (text box) frmRepair
1
by: KMEscherich | last post by:
Platform = Windows Program = Access 2003 Hi there, I am stumpped!! I am attempting to populate a form control as follows: I have a form that has 2 drop-down boxes. One retrieves the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.