|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. jstucklex@attglobal.net ================== |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message news:m5-dnZd-7K7Q35DVnZ2dnUVZ_uqdnZ2d@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? |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Tue, 22 Apr 2008 11:08:06 +0500, in comp.lang.php "freelance71"
<f93c0532@yahoo.com> <fujvcb$149$1@registered.motzarella.org> wrote: >| >| "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message >| news:m5-dnZd-7K7Q35DVnZ2dnUVZ_uqdnZ2d@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. -- ------------------------------------------------------------- jnorthau@yourpantsyahoo.com.au : Remove your pants to reply -- ------------------------------------------------------------- |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
freelance71 wrote:
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message > news:m5-dnZd-7K7Q35DVnZ2dnUVZ_uqdnZ2d@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. jstucklex@attglobal.net ================== |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Apr 22, 7:23 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> freelance71 wrote: > > "Jerry Stuckle" <jstuck...@attglobal.net> wrote in message > >news:m5-dnZd-7K7Q35DVnZ2dnUVZ_uqdnZ2d@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; } |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On Tue, 22 Apr 2008 10:11:31 -0700 (PDT), venti wrote:
> On Apr 22, 7:23 am, Jerry Stuckle <jstuck...@attglobal.net> wrote: >> freelance71 wrote: >> > "Jerry Stuckle" <jstuck...@attglobal.net> wrote in message >> >news:m5-dnZd-7K7Q35DVnZ2dnUVZ_uqdnZ2d@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? |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
> #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. |
|
![]() |
| Outils de la discussion | |
|
|