Page 1 of 1

HTML form Select Option display MySql database query

Posted: Thu Aug 17, 2006 6:00 pm
by kosalayb
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have a database created in MySql, which has company information such as area code, address1, email and webaddress.
In the html form,  when the user select the area code from the pull down menu without hiting any other button( Form/Select /Option ) , company information in that area should be displayed. 

I wrote a php program (server.php)to read data from the database

Code: Select all

<?php

$user="root";
$password="";
$database="bombay";
mysql_connect("kosala",$user,$password);
@mysql_select_db($database) or die("Unable to select database");

$item = $_REQUEST['item'];
echo "Option Selected : $item <br> ";

$query= "SELECT * FROM Bombayt0 ";
$result=mysql_query($query);

$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i<$num){
	$CName=mysql_result($result,$i,"CName");
	$CAdd=mysql_result($result,$i,"CAdd");
	$CPCode=mysql_result($result,$i,"CPCode");
	$CAdd=mysql_result($result,$i,"CAdd");
	$CTel=mysql_result($result,$i,"CTel");
	$CFax=mysql_result($result,$i,"CFax");
	$CEmail=mysql_result($result,$i,"CEmail");
	$CWeb=mysql_result($result,$i,"CWeb");

                  $i++;
}

?>
I created a html program(client.html)

Code: Select all

<html>
<head>
<script language="javascript" src="server.php"> 
</script>

</head>

<body>

<form name="form" >
<select method="post" name="item" onChange="go()">
<option value="1" > 1 </option> 
<option value="2" > 2 </option> 
</select>


<script type="text/javascript">
var selectedItem = 0;

function go(){
	box=document.forms[0].item;
	selectedItem = document.forms[0].item.options[box.selectedIndex].value;
}
</script>

Company Name: <input type="text" name="CName" > <br>
Company Addr: <input type="text" name="CAdd" ><br>
Phone: <input type="text" name="CTel" ><br>
Fax: <input type="text" name="fax" ><br>
E-mail: <input type="text" name="CEmail" ><br>
Web: <input type="text" name="CWeb" ><br> 

</form>

</body>
</html>

how can i pass $result from server.php program to client.html? actually what is the best solution for this problem?

tx


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Aug 17, 2006 6:14 pm
by feyd
make server.php write client.html (to the browser.)

Posted: Thu Aug 17, 2006 8:32 pm
by Ollie Saunders

Code: Select all

$i=0;
while ($i<$num){
        $CName=mysql_result($result,$i,"CName");
        $CAdd=mysql_result($result,$i,"CAdd");
        $CPCode=mysql_result($result,$i,"CPCode");
        $CAdd=mysql_result($result,$i,"CAdd");
        $CTel=mysql_result($result,$i,"CTel");
        $CFax=mysql_result($result,$i,"CFax");
        $CEmail=mysql_result($result,$i,"CEmail");
        $CWeb=mysql_result($result,$i,"CWeb");

                  $i++;
}
Somone has for phobia :P
In the html form, when the user select the area code from the pull down menu without hiting any other button( Form/Select /Option ) , company information in that area should be displayed.
Well you'll have to add some JavaScript to submit the form immediately after they make the choice then you'll be able to repopulate the form in anyway you like. onchange="this.form.submit()" should do it. In your PHP you can distingish between a user submission via <button> or <input type="submit"> and the one generated by JS by testing the existance of the button or input.

Posted: Sun Aug 20, 2006 10:17 am
by kosalayb
feyd wrote:make server.php write client.html (to the browser.)
well, could you pl explain this more?

Re: HTML form Select Option display MySql database query

Posted: Sun Aug 20, 2006 10:46 am
by RobertGonzalez
kosalayb wrote:In the html form, when the user select the area code from the pull down menu without hiting any other button( Form/Select /Option ) , company information in that area should be displayed.
This implies client side activity. Is that what you are looking for? When a user selects something from drop down it will automatically populate the rest of the form (or parts of it)? please clarify because if this is the case I need to move this thread to Client Side.

Posted: Sun Aug 20, 2006 10:53 am
by RobertGonzalez
Per PM:
kosalayb wrote:Yes, This is client side. When the user select an option from the pull down menue( ex: area code), server side php should populate, read data from the database and pass to the client side html.
This is being moved to client side.

yep

Posted: Sun Aug 20, 2006 11:00 am
by kosalayb
Everah wrote:Per PM:
kosalayb wrote:Yes, This is client side. When the user select an option from the pull down menue( ex: area code), server side php should populate, read data from the database and pass to the client side html.
This is being moved to client side.
yep. When the pull down menue select the are code(ex:02), company names in that area should be displayed on the same page.company names are stored in Mysql database and php is used to read data.