Jump to content

Php Script Problem For Drop Down Menu When The Page Refreshing


Amarnath

Recommended Posts

good morning friends,here i'm new to this schools forum.. any way i hope i'll get best result for my problem ... nd thanx for reading this topic sir.my intension is develop a php form for displaying data from the one of the table of mysql database and adding the other columns and store them to other table in the mysql database.php script containing the dropdown menu, text boxes and the list of database columns from the database.my idea to display data is like this..when i select a dropdown menu(the drop down menu list containing list of contents generates from database) then next the text field should be populated with the data related to the selected option(from the database) and also i should get the other two columns of data below the dropdown menu nd textfield...Note: the dropdown list values and the textfied values are unique and they contains other two columns of data as shown belowfor dropdown menu(vehicleno) locationID time displaying these 2 columns when selected dropdownmenu this scheid to display in the textbox.vehicleno: locationID time scheidv001 l001 4:00 AM sch01 v001 l002 6:00 AM sch01v001 l003 7:00 AM sch01v002 l005 8:00 AM sch02 v002 l006 9:00 AM sch02v002 l007 10:00 AM sch02i used javascript <script type=text/javascript>function fn(ele) { var selected = ele.options[ele.selectedIndex].value; location.href="new4.php?test=" + selected;} </script>where the selected is the dropdown selected value and after selecting the option in dropdown menu then the php page refreshes and changing the selected option in the dropdown menu.can any one solve this problem.thanks in advance.

Link to comment
Share on other sites

What's the problem? You can have the new4.php page get the "test" value from $_GET and look up the information from the database, right?
Thanks for replying...Good Morning Friend,Here is my code wat i did and also i attached the image wat i did.In this if the page is refreshed then the drop down menu comes to the initial sate of the value so that i printed at the end for knowing that selected value is getting or not. the scheduleID is related to the print vehicle number.Plz help me..http://rapidshare.com/files/260866781/New_Picture.bmp.html<script type="text/javascript">function makeDisable(){ var x=document.getElementById("str_repvehicle1") x.disabled=true}function makeEnable(){ var x=document.getElementById("str_repvehicle1") x.disabled=false}</script><style type="text/css">@import "timejs/jquery.timeentry.css";</style><script type="text/javascript" src="timejs/jquery-1.3.2.js"></script><script type="text/javascript" src="timejs/jquery.timeentry.js"></script><script language="JavaScript">/*begin script for other check box*/<!--function enable_text(status){status=!status; document.frmschinfo.txtother.disabled = status;}//-->/*end script for other check box*/</script><script language=Javascript>//begin code to show the schID in text boxfunction Choice(){var x = document.getElementById("txtschid");var y = document.getElementById("strvehicle");x.value = y.options[y.selectedIndex].title;}/*begin code to show the schID in text box*/</script><script type=text/javascript>function fn(ele) { var selected = ele.options[ele.selectedIndex].value; var selected1 = ele.options[ele.selectedIndex].title; location.href="schtracking_new2.php?test=" + selected + "&test1=" + selected1;} </script> // php code starts<?phpecho '<link rel="stylesheet" href="announcement-himsw.css" type="text/css"/>';$db_host = 'localhost';$db_user = 'username;$db_pwd = 'pwd';$database = 'tracking';$table = 'schedule_mas1';$vehicleid = "Vehicle ID";$space = " ";$scheduleid="Schedule ID";$date = "Date :";$test = $_GET['test'];$test1 = $_GET['test1'];if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database");if (!mysql_select_db($database)) die("Can't select database");//to get vehicle number to dropdown list code starts here$vehlist = mysql_query("SELECT DISTINCT sch_id, veh_no FROM {$table}");if (!$vehlist){ die("Query to show fields from table failed");}$fields_num1 = mysql_num_fields($vehlist);echo "<p class='innerhead'>Schedule Tracking Info..</p>";echo "<form name='frmschinfo' method='post' action='' onSubmit=''>";echo "<table width='800px', border='0'><tr>";echo "<td class='gentext' width='150px'>$vehicleid</td>";echo "<td class='gentext' width='100px'><select id='strvehicle' name='strvehicle' onchange='Choice(); fn(this);'>";for($k=1; $k<$fields_num1; $k++){ $field1 = mysql_fetch_field($vehlist); }while($row1 = mysql_fetch_array($vehlist)){//foreach($row1 as $cell1) //echo "<option value='$cell1'>$cell1</option>";echo "<option value=\"$row1[veh_no]\" title=\"$row1[sch_id]\">$row1[veh_no]</option>";}echo "</select></td>";echo "<td class='gentext' width='50px'>$space</td>";echo "<td class='gentext' width='150px'>$scheduleid</td>";echo "<td class='gentext' width='70px'><input name='txtschid' id='txtschid' type='text' size='25' maxlength='50' value='{$test1}' /></td>";echo "<td class='gentext' width='50px'>$space</td>";echo "<td class='gentext' width='80px'>$date</td>";echo "<td class='gentext' width='70px'><input name='txtdate' type='text' id='txtdate' size='20' maxlength='30' /></td>";echo "<td width='50px'><img src='images/Calander.gif' alt='calendar' width='21' height='18' border='0'/></td>";echo "</tr>";echo "<tr><td class='gentext'><input type='checkbox' name=others onClick='enable_text(this.checked)' >Others</label></td>";echo "<td class='gentext' width='100px'><input name='txtother' type='text' id='txtdate' size='25' maxlength='30' /></td>";echo "</tr>";echo "<tr><td> </td></tr>";echo "</table>\n";mysql_free_result($vehlist);//vehicle list ends here$result = mysql_query("SELECT ID,loc_id,bin_no,lift_time FROM {$table} where veh_no = '$test'");// sending query$result = mysql_query("SELECT * FROM {$table}");if (!$result) { die("Query to show fields from table failed");}$fields_num = mysql_num_fields($result);echo "<table width='950px', border='0', class='tableborder'><tr>";// printing table headersecho "<td align='center' bgcolor='#0071BC' width='120px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Sl. No.</td>";echo "<td align='center' bgcolor='#0071BC' width='120px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Location ID</td>";echo "<td align='center' bgcolor='#0071BC' width='70px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>No.of Bins</td>";echo "<td align='center' bgcolor='#0071BC' width='120px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Proposed Lift Time</td>";echo "<td align='center' bgcolor='#0071BC' width='250px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Actual Lifting Time</td>";echo "<td align='center' bgcolor='#0071BC' width='100px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;'>Weight</td>";echo "<td align='center' bgcolor='#0071BC' width='70px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Vehicle Status</td>";echo "<td align='center' bgcolor='#0071BC' width='100px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Replaced Vehicle</td>";echo "<td align='center' bgcolor='#0071BC' width='100px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Comments</td>";echo "</tr>\n";for($i=1; $i<$fields_num; $i++){ $field = mysql_fetch_field($result); }// printing table rows$j=0;while($row = mysql_fetch_row($result)){echo "<tr class='gentext' style='padding-top:2px; padding-bottom:2px;'>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable do{$j++;foreach($row as $cell) echo "<td class='gentext' width='120px'>$cell</td>";echo "<td class='gentext' width='250px' align='center'><input type='text' id='mytime$j' Name='stract_time$j' maxlength='20' size='15'></td>";echo "<td class='gentext' width='100px' align='center'><input type='text' Name='strweight$j' maxlength='6' size='10'></td>";echo "<td class='gentext' width='100px' align='center'><input type='button' onclick='makeDisable()' value='Act' name='veh_stat$j' class='gentext'><input type='button' onclick='makeEnable()' value='Brk' name='veh_stat$j' class='gentext'></td>"; //printing replaced vehicle Drop Down..$repvehlist = mysql_query("SELECT DISTINCT veh_no FROM {$table}");if (!$repvehlist){ die("Query to show fields from table failed");}$fields_num6 = mysql_num_fields($repvehlist);echo "<td class='gentext' width='100px'><select name='str_repvehicle$j' disabled>";for($r=1; $r<$fields_num6; $r++){ $field6 = mysql_fetch_field($repvehlist); }while($row6 = mysql_fetch_row($repvehlist)){foreach($row6 as $cell6) echo "<option value='$cell6'>$cell6</option>";}echo "</select></td>";mysql_free_result($repvehlist);//end printing replaced vehicle Drop Down.. echo "<td class='gentext' width='100px' align='center'><input type='text' Name='strcomments$j' maxlength='200' size='25'></td>";echo "<script>";echo "$(function () { $('#mytime$j').timeEntry();";echo "});";echo "</script>";}while ($j<=EOF);echo "</tr>\n";}mysql_free_result($result);?>5338504939.jpgin the above image my deisgned for were the vehicleID is brought from database and scheduleID to the text box is also from the database and the si.no,locationID anddate are also from the same database table ..i want to store this exact data in to the another table by filling the forms by the user.can any one say that how can i store all the values into another table. were vehicleID and ScheduleID are same for the si.no,locationID ,date actual date, comments,weight and so on.Thanks in Advance..
Link to comment
Share on other sites

What's the problem? You can have the new4.php page get the "test" value from $_GET and look up the information from the database, right?
Thanks for replying friend,http://rapidshare.com/files/260866781/New_Picture.bmp.htmlhere is the above link for my form layout.form Contains VehicleID,scheduleID,date,others and different columns like si.no,locationID,time,actual time,.... these should be inserted in to the database table at a time. how it is possible can u plz give me some solution..the vehicleID is selected and as per the selection there is a text box and several records which are populated by from the single table of mysql database. i use to store these remaining values after filling by the user to the another table in that database.
<?phpecho '<link rel="stylesheet" href="announcement-himsw.css" type="text/css"/>';$db_host = 'localhost';$db_user = 'username';$db_pwd = 'pwd';$database = 'test';$table = 'schedule_mas1';$vehicleid = "Vehicle ID";$space = "		  ";$scheduleid="Schedule ID";$date = "Date  :";//$dollar="$";$test = $_GET['test'];$test1 = $_GET['test1'];if (!mysql_connect($db_host, $db_user, $db_pwd))	die("Can't connect to database");if (!mysql_select_db($database))	die("Can't select database");//to get vehicle number to dropdown list code starts here$vehlist = mysql_query("SELECT DISTINCT sch_id, veh_no  FROM {$table}");if (!$vehlist){	die("Query to show fields from table failed");}$fields_num1 = mysql_num_fields($vehlist);echo "<p class='innerhead'>Schedule Tracking Info..</p>";echo "<form name='frmschinfo' method='post' action='' onSubmit=''>";echo "<table width='800px', border='0'><tr>";echo "<td class='gentext' width='150px'>$vehicleid</td>";echo "<td class='gentext' width='100px'><select id='strvehicle' name='strvehicle' onchange='Choice(); fn(this);'>";for($k=1; $k<$fields_num1; $k++){	$field1 = mysql_fetch_field($vehlist);	}while($row1 = mysql_fetch_array($vehlist)){//foreach($row1 as $cell1)  				//echo  "<option value='$cell1'>$cell1</option>";				echo "<option value=\"$row1[veh_no]\" title=\"$row1[sch_id]\">$row1[veh_no]</option>";}echo "</select></td>";echo "<td class='gentext' width='50px'>$space</td>";echo "<td class='gentext' width='150px'>$scheduleid</td>";echo "<td class='gentext' width='70px'><input name='txtschid' id='txtschid' type='text' size='25' maxlength='50' value='{$test1}' /></td>";echo "<td class='gentext' width='50px'>$space</td>";echo "<td class='gentext' width='80px'>$date</td>";echo "<td class='gentext' width='70px'><input name='txtdate' type='text' id='txtdate' size='20' maxlength='30' /></td>";echo "<td width='50px'><img src='images/Calander.gif' alt='calendar' width='21' height='18' border='0'/></td>";echo "</tr>";echo "<tr><td class='gentext'><input type='checkbox' name=others onClick='enable_text(this.checked)' >Others</label></td>";echo "<td class='gentext' width='100px'><input name='txtother' type='text' id='txtdate' size='25' maxlength='30' /></td>";echo "</tr>";echo "<tr><td> </td></tr>";echo "</table>\n";mysql_free_result($vehlist);//vehicle list ends here$result = mysql_query("SELECT ID,loc_id,bin_no,lift_time FROM {$table} where veh_no = '$test'");// sending query$result = mysql_query("SELECT * FROM {$table}");if (!$result) {	die("Query to show fields from table failed");}$fields_num = mysql_num_fields($result);echo "<table width='950px', border='0', class='tableborder'><tr>";// printing table headersecho "<td align='center' bgcolor='#0071BC' width='120px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Sl. No.</td>";echo "<td align='center' bgcolor='#0071BC' width='120px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Location ID</td>";echo "<td align='center' bgcolor='#0071BC' width='70px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>No.of Bins</td>";echo "<td align='center' bgcolor='#0071BC' width='120px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Proposed Lift Time</td>";echo "<td align='center' bgcolor='#0071BC' width='250px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Actual Lifting Time</td>";echo "<td align='center' bgcolor='#0071BC' width='100px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;'>Weight</td>";echo "<td align='center' bgcolor='#0071BC' width='70px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Vehicle Status</td>";echo "<td align='center' bgcolor='#0071BC' width='100px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Replaced Vehicle</td>";echo "<td align='center' bgcolor='#0071BC' width='100px' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 10px; color: #ffffff; padding-top: 5px; padding-bottom:5px;' align='center'>Comments</td>";echo "</tr>\n";for($i=1; $i<$fields_num; $i++){	$field = mysql_fetch_field($result);	}// printing table rows$j=0;while($row = mysql_fetch_row($result)){echo "<tr class='gentext' style='padding-top:2px; padding-bottom:2px;'>";	// $row is array... foreach( .. ) puts every element	// of $row to $cell variable	do{$j++;foreach($row as $cell)	 echo "<td class='gentext' width='120px'>$cell</td>";echo "<td class='gentext' width='250px' align='center'><input type='text' id='mytime$j' Name='stract_time$j' maxlength='20' size='15'></td>";echo "<td class='gentext' width='100px' align='center'><input type='text' Name='strweight$j' maxlength='6' size='10'></td>";echo "<td class='gentext' width='100px' align='center'><input type='button' onclick='makeDisable()' value='Act' name='veh_stat$j' class='gentext'><input type='button' onclick='makeEnable()' value='Brk' name='veh_stat$j' class='gentext'></td>";									//printing replaced vehicle Drop Down..$repvehlist = mysql_query("SELECT DISTINCT veh_no  FROM {$table}");if (!$repvehlist){	die("Query to show fields from table failed");}$fields_num6 = mysql_num_fields($repvehlist);echo "<td class='gentext' width='100px'><select name='str_repvehicle$j' disabled>";for($r=1; $r<$fields_num6; $r++){	$field6 = mysql_fetch_field($repvehlist);	}while($row6 = mysql_fetch_row($repvehlist)){foreach($row6 as $cell6)  				echo  "<option value='$cell6'>$cell6</option>";}echo "</select></td>";mysql_free_result($repvehlist);//end printing replaced vehicle Drop Down..									echo "<td class='gentext' width='100px' align='center'><input type='text' Name='strcomments$j' maxlength='200' size='25'></td>";echo "<script>";echo "$(function () { $('#mytime$j').timeEntry();";echo "});";echo "</script>";}while ($j<=EOF);echo "</tr>\n";}mysql_free_result($result);?>

http://rapidshare.com/files/260866781/New_Picture.bmp.html-----------------------------------------------------------------------another request of me that i want to write store procedure for mysql database by php..i want that how they are written in our php application and how to retrieve the data from that values record by record from a set of sql statements.Thanks In advance.

Link to comment
Share on other sites

Check this thread for information on processing forms:http://w3schools.invisionzone.com/index.php?showtopic=12509There's also a PHP forms tutorial on w3schools you might find helpful. Once you have the data from the form, you can use a INSERT SQL query to add the information to your database, or an UPDATE query to update what's already there.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...