I have a table from which I populate a list box.

I need to display/edit the details of the particular record which I click on, which has to be retrieved from the same table from which the list box is populated. I need the correct coding for both the events. Both the events should be displayed in the same screen. I have developed the following code which populates the listbox, but does not retrieve the record which has been clicked in the list Box. Members are requested to kindly help me with the correct code.

<HTML>
<HEAD>
<body style="background:#80BFFF">
<H1><CENTER><u>VENDOR MASTER DATA MODIFICATION SCREEN</u></center></H1>

<html> 
<body bgcolor=#ffffff> 
<form action="amend2.php" action="get"> 
<name="row">
<table width=300 align=center> 
<tr><td>VENDOR NAME:</td><td>

<?php 
$hostname = "localhost";
$db_user = "root";
$db_password = "";
$database = "t2";  
$db_table = "vendmast";  
$db = mysql_connect($hostname, $db_user, $db_password); 
mysql_select_db($database,$db);
$query = "select vend_des From $db_table order by vend_des"; 
$results = mysql_query($query, $db) or die("Error performing query"); 

echo("<select name=\"selectItem\">"); 
while($row = mysql_fetch_object($results))
{ 
echo("<option value=>$row->vend_des</option>"); 
} 
mysql_close($db);

?>
</td></tr> 
<td></td><td><input type=submit></td></tr> 
</table> 
</form> 
</body> 
</html>
<?php 
$hostname = "localhost";
$db_user = "root";
$db_password = "";
$database = "t2";  
$db_table = "vendmast";  
$db = mysql_connect($hostname, $db_user, $db_password); 
mysql_select_db($database,$db);
$query = "select vend_des From $db_table order by vend_des where vend_des='<option value=>$row->vend_des</option>'"; 
$results = mysql_query($query, $db) or die("Error performing query"); 
echo vend_des;
?>

Hi Surya,
First of all I didn't understand your requirement properly, but i found a minor mistake in your code,
please check the following you can understand

echo("<select name=\"selectItem\">"); 
while($row = mysql_fetch_object($results))
{ 
echo("<option value='".you should have your database retrieved value here, some thing like $row->id."'>$row->vend_des</option>"); 
}

I have a table from which I populate a list box.

I need to display/edit the details of the particular record which I click on, which has to be retrieved from the same table from which the list box is populated. I need the correct coding for both the events. Both the events should be displayed in the same screen. I have developed the following code which populates the listbox, but does not retrieve the record which has been clicked in the list Box. Members are requested to kindly help me with the correct code.

<HTML>
<HEAD>
<body style="background:#80BFFF">
<H1><CENTER><u>VENDOR MASTER DATA MODIFICATION SCREEN</u></center></H1>

<html>
<body bgcolor=#ffffff>
<form action="amend2.php" action="get">
<name="row">
<table width=300 align=center>
<tr><td>VENDOR NAME:</td><td>

<?php
$hostname = "localhost";
$db_user = "root";
$db_password = "";
$database = "t2";
$db_table = "vendmast";
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
$query = "select vend_des From $db_table order by vend_des";
$results = mysql_query($query, $db) or die("Error performing query");

echo("<select name=\"selectItem\">");
while($row = mysql_fetch_object($results))
{
echo("<option value=>$row->vend_des</option>");
}
mysql_close($db);

?>
</td></tr>
<td></td><td><input type=submit></td></tr>
</table>
</form>
</body>
</html>

<?php
$hostname = "localhost";
$db_user = "root";
$db_password = "";
$database = "t2";
$db_table = "vendmast";
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
$query = "select vend_des From $db_table order by vend_des where vend_des='<option value=>$row->vend_des</option>'";
$results = mysql_query($query, $db) or die("Error performing query");
echo vend_des;
?>

Mr. Saiprem,

To clarify my requirement, I state as under:
a. I have a table in which I have vendors master data.
b. To edit/modify the vendors data, I need to display the vendors list from the table on to a list box.
c. From the listbox, I need to display the details of the vendor which is selected from the List Box by clicking on the same.
d. As soon as the vendors name is selected, the details of the vendor are to be displayed in the same screen below the listbox so that the details can be modified or edited and saved back in the table.
e. The table which is used to populate the listbox and the display of the vendors details on the screen is the same.
f. The code has been written by me has some problems and is not giving the desired results.
g. I would request you to kindly modify the code and help me out.

Suryanarayanan

Hi Surya,
First of all I didn't understand your requirement properly, but i found a minor mistake in your code,
please check the following you can understand

echo("<select name=\"selectItem\">"); 
while($row = mysql_fetch_object($results))
{ 
echo("<option value='".you should have your database retrieved value here, some thing like $row->id."'>$row->vend_des</option>"); 
}

I am assuming that there will be an id(primary key) for the vendor description in your database

<HTML>
<HEAD>
<body style="background:#80BFFF">
<H1><CENTER><u>VENDOR MASTER DATA MODIFICATION SCREEN</u></center></H1>
<html>
<body bgcolor=#ffffff>
<form action="amend2.php" action="get">
<table width=300 align=center>
<tr><td>VENDOR NAME:</td><td>
<td>
<?php
$hostname = "localhost";
$db_user = "root";
$db_password = "";
$database = "t2";
$db_table = "vendmast";
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
$query = "select vend_id, vend_des From $db_table order by vend_des";
$results = mysql_query($query, $db) or die("Error performing query");
echo "<select name=\"selectItem\" onchange='javascript:this.form.submit'>");
while($row = mysql_fetch_object($results))
{
	echo"<option value='".$row->vend_id."'>".$row->vend_des."</option><br />";
}
mysql_close($db);
?>
</select>
</td></tr>
<td></td><td><input type=submit></td></tr>
</table>
</form>
</body>
</html>

<?php
if(isset($_POST['selectItem']) && $_POST['selectItem']!='')
{
	$query = "select vend_des From $db_table order by vend_des where vend_id='".$_POST['selectItem']."'";
	$results = mysql_query($query, $db) or die("Error performing query");
	$row = mysql_fetch_object($results)
	echo $row->vend_des;
}
?>

Thanks Saiprem. the List Box gets populated, but the selected name in the listbox is not appearing.

Do we have to end the javascript you have invoked in the coding?

Regards,

Suryanarayanan

I am assuming that there will be an id(primary key) for the vendor description in your database

<HTML>
<HEAD>
<body style="background:#80BFFF">
<H1><CENTER><u>VENDOR MASTER DATA MODIFICATION SCREEN</u></center></H1>
<html>
<body bgcolor=#ffffff>
<form action="amend2.php" action="get">
<table width=300 align=center>
<tr><td>VENDOR NAME:</td><td>
<td>
<?php
$hostname = "localhost";
$db_user = "root";
$db_password = "";
$database = "t2";
$db_table = "vendmast";
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
$query = "select vend_id, vend_des From $db_table order by vend_des";
$results = mysql_query($query, $db) or die("Error performing query");
echo "<select name=\"selectItem\" onchange='javascript:this.form.submit'>");
while($row = mysql_fetch_object($results))
{
	echo"<option value='".$row->vend_id."'>".$row->vend_des."</option><br />";
}
mysql_close($db);
?>
</select>
</td></tr>
<td></td><td><input type=submit></td></tr>
</table>
</form>
</body>
</html>

<?php
if(isset($_POST['selectItem']) && $_POST['selectItem']!='')
{
	$query = "select vend_des From $db_table order by vend_des where vend_id='".$_POST['selectItem']."'";
	$results = mysql_query($query, $db) or die("Error performing query");
	$row = mysql_fetch_object($results)
	echo $row->vend_des;
}
?>

Yes you are right, I did mistake in writing it, it should be like

echo "<select name=\"selectItem\" onChange='javascript:this.form.submit();'>");

Thanks Saiprem. the List Box gets populated, but the selected name in the listbox is not appearing.

Do we have to end the javascript you have invoked in the coding?

Regards,

Suryanarayanan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.