Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 19th, 2005, 04:46 AM
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help in php

Hi,

I need some help in PHP. i have a page named test.php which contain a list box. The list box have id. Whenever i choose a id i have to show the info belongs to the id in the same page that is in the test.php. The info are in the database with the id. I m using php and javascript

I think u understand the prob, if not, inform me.

Thanks

 
Old February 19th, 2005, 07:14 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

You can do this in two ways.

1) Using XML. Please have a look at the sample XML code given at

http://p2p.wrox.com/topic.asp?TOPIC_ID=25686

This is in ASP. But PHP provides the same technology.

2) using Javascript.

Fetch the texts associated with ids and store them in hidden fields. Let the names of hidden fields be created as hid_<id>. Let the name of form be frm_dynamic

Create a place holder for text. This can be a table cell or a div. You need to give an id for this. Let this id be id_place_holder.

Then, in the onchange event of the combo, you can write a javascript. Get the value of the chosen id. Get the corresponding text from hidden field. Display it in the place holder. Following code will do this.

var i_current_id=document.frm_dynamic.cbo_id.options[document.frm_dynamic. cbo_id.selectedIndex].value;
var str_text=eval('document.frm_dynamic.hid_'+i_curren t_id+'.value');
var obj_place_holder=document.getElementById("id_place _holder");
obj_place_holder.innerHTML=str_text;
 
Old February 19th, 2005, 11:57 AM
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks madhukp for the quick reply. But the main problem is (i think) i have to get the id and then i have query to the database. And then show the info in the same page. That is first i have to get the id by JavaScript then with that id i have to query by php in the db. And i think this is the hard part. I think i may clear the prob

 
Old February 21st, 2005, 01:03 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

ok, that is what I have said in the earlier part. The db query you can do in the beginning and fetch all the values corresponding to each id and store them in hidden fields. Suppose you have ids going from 1 to 10, you will have 10 hidden fields in the form. Each of these contain the value corresponding to one id. Then show the appropriate value from them as the selection changes.

This will cause problem when number of elements in the select box increases. Then you will have to use either refresh method or XML method.

In the refresh method, you will simply submit the form containing select box and in the page, you will fetch and display the corresponding value when there is submitted value of id. That is, in the onchange event of select box submit the form to the same page. In the page, check whether the submitted value of id is null. If it is not null, you can query the database and display relevant value corresponding to the submitted id. Hope you understood.
 
Old February 24th, 2005, 10:47 PM
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry that i do not understant you...and thanks for explain the solution beautifully..and again sorry for the late reply..

Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
Beg. PHP 5 > Ch. 11 - fetch_field.php crater BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 January 2nd, 2007 12:20 PM
PHP Warning: PHP Startup: Unable to load dynamic l surendran Beginning PHP 1 May 29th, 2006 08:49 AM
begin php & mysql - chapter 12, user_form.php jon_stubber Beginning PHP 1 March 9th, 2006 10:57 AM
Error: movie.php & commit.php on p182-186, ch6 willburke BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 12th, 2004 02:48 PM
Ch. 1: PHP Installation Troubles: php3 vs php manjito BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 4 June 12th, 2003 03:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.