Jump to content

Autofill Drop Down List


mikebyrne

Recommended Posts

Im trying to autofill at dropdown list with the contents from the field "ProductName" from the products table

 

At present I've manually filled in the options

 

<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>

				<td width="55">product</td>
				<td width="762">
<select name="month">
<option value="">------</option>
<option value="1" >100% btrax - Bollene Saffron</option>	
<option value="2" >100% btrax - Cassis Plum</option>
<option value="3" >btrax cotton blend - Rustique Almond Green</option>

<option value="4" >btrax cotton blendr - Border Grill, Earth Green</option>
<option value="5" >btrax Black Toast & Marmalade - Black Toast & Marmalade Rectangular Baking Dish</option>
<option value="6" >btrax body care - Buckwheat Buffing Soap For Feet</option>
</select>
			  </td>
			</tr>
	  </table>

Link to comment
Share on other sites

Something like this?

<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>

				<td width="55">product</td>
				<td width="762">
<select name="month">
<option value="">------</option>
<?
$i=1;
while ($row = mysql_fetch_array($query))
{
echo "<option value=\"$i\" >".$row['ProductName']."</option>";
$i++;
}
?>
</select>
			  </td>
			</tr>
	  </table>

Link to comment
Share on other sites

yes

 

nclude('adminconnect.php');
$query = "SELECT ProductName  FROM Product;
$result = mysql_query($query) or die (mysql_error());

<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>

				<td width="55">product</td>
				<td width="762">
<select name="month">
<option value="">------</option>
<?
$i=1;
while ($row = mysql_fetch_array($query))
{
echo "<option value=\"$i\" >".$row['ProductName']."</option>";
$i++;
}
?>
</select>
			  </td>
			</tr>
	  </table>

Link to comment
Share on other sites

I just get

 

include('adminconnect.php'); $query = "SELECT ProductName FROM Product; $result = mysql_query($query) or die (mysql_error());

 

as output on the page

 

My code is

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin Page | sales</title>
<link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="../includes/wrapper.js"></script>
</head>
<body>
<div id="Box">

<div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../images/logo.gif" width="51" height="125" border="0" /></a></div>
<div id="contentBox">
<form>


<!-- logo start -->
<div id="container">
	<div class="padTop28"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>

<!-- logo finish -->



<!-- menu start -->
<div id="container">
			<div id="menu1">
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/start.php" class="black">Order</a></div>

		<div id="menu_space1"><!-- --></div>
		<div id="menu_on"><!-- --></div>
            <div id="menu_text_on"><a href="../admin_files/sales.php" class="black_on">Sales</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/list.php" class="black">Edit item</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>

		<div id="menu_text_off"><a href="../admin_files/sales.php" class="black">Postage fee</a></div>
		<div id="menu_space1"><!-- --></div>
            <div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../admin_files/adminreg.php" class="black">Add User</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../admin_files/add.php" class="black">Add Product</a></div>
		<div id="menu_space1"><!-- --></div>
	</div>

	<div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="dotted"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="menu2">

		<div id="menu_hide"><!-- --></div>
		<div id="menu_text_off" class="textWhite">order</div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_hide"><!-- --></div>
		<div id="menu_text_off"><a href="sales.php" class="black">Sales</a></div>
		<div id="menu_space2"><!-- --></div>
		<div id="menu_text_on"><a href="sales_search.php" class="black_on">Sales search</a></div>

		<div class="clr"><!-- --></div>
	</div>
	<div class="clr"><!-- --></div>
	<div class="padTop38"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- menu finish -->



<!-- top start -->

<div id="container">
	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="titleText">sales search</div>

	<div class="clr"><!-- --></div>
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- top finish -->



<!-- 1px space start -->
<div id="containerBg1">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- 1px space finish -->



<!-- data top start -->
<div id="containerBg3">
	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>

</div>
<div class="clr"><!-- --></div>
<!-- data top finish -->



<!-- data content start -->
<div id="containerBg4">

	<!-- data start -->
	<div class="padTop11"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div class="padTop1">

		<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>
				<td width="55">month</td>
				<td width="762">
<select name="month" class="000">
<option value="">------</option>
<option value="2006-06" >2006-06</option>

<option value="2006-05" >2006-05</option>
<option value="2006-04" >2006-04</option>
<option value="2006-03" >2006-03</option>
<option value="2006-02" >2006-02</option>
<option value="2006-01" >2006-01</option>
<option value="2005-12" >2005-12</option>

</select>
			  </td>
			</tr>
	  </table>
	</div>
	<div class="clr"><!-- --></div>
	<div class="padTop11"><!-- --></div>
	<div class="clr"><!-- --></div>
	<!-- data finish -->


	<!-- data start -->
	<div class="padTop1">
		<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>
				<td width="55">year</td>
				<td width="762">
<select name="year" class="">
<option value="">------</option>

<option value="2006" >2006</option>
<option value="2005" >2005</option>
</select>
			  </td>
			</tr>
	  </table>
	</div>
	<!-- data finish -->



	<!-- line start -->
	<div class="clr"><!-- --></div>
	<div class="padTop11"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="dottedIn"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="sales_text_and">and / or</div>
	<div id="dottedIn"><!-- --></div>

	<div class="clr"><!-- --></div>
	<div class="padTop11"><!-- --></div>
	<div class="clr"><!-- --></div>
	<!-- line finish -->


	<!-- data start -->
	<div class="padTop1">

include('adminconnect.php');
$query = "SELECT ProductName  FROM Product;
$result = mysql_query($query) or die (mysql_error());

<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>

				<td width="55">product</td>
				<td width="762">
<select name="month">
<option value="">------</option>
<?PHP
$i=1;
while ($row = mysql_fetch_array($query))
{
echo "<option value=\"$i\" >".$row['ProductName']."</option>";
$i++;
}
?>
</select>
			  </td>
			</tr>
	  </table>

	</div>
	<div class="clr"><!-- --></div>
	<div class="padTop11"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="dottedIn"><!-- --></div>
	<div class="clr"><!-- --></div>
	<!-- data finish -->


	<!-- btn start -->
	<div class="padTop16"><!-- --></div>

	<div class="clr"><!-- --></div>
	<div id="btn"><a href="sales_search_result.php"><img src="../images/btn_search.gif" alt="search" width="73" height="23" border="0" /></a></div>
	<div class="clr"><!-- --></div>
	<div class="padTop16"><!-- --></div>
	<div class="clr"><!-- --></div>
	<!-- btn finish -->


</div>
<div class="clr"><!-- --></div>
<!-- data content finish -->




<!-- data btm start -->
<div id="containerBg3">
	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data btm finish -->



<!-- btm start -->
<div id="containerBg1">

	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div id="container">
	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div class="padTop16"><!-- --></div>

<div class="clr"><!-- --></div>
<!-- btm finish -->

</form>
</div>

</div>
</body>
</html>

 

 

 

Link to comment
Share on other sites

That is because it is not inside of the PHP tags. Move then down:

<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>

				<td width="55">product</td>
				<td width="762">
<select name="month">
<option value="">------</option>
<?PHP
include('adminconnect.php');
$query = "SELECT ProductName  FROM Products;
$result = mysql_query($query) or die (mysql_error());
$i=1;
while ($row = mysql_fetch_array($query))
{
echo "<option value=\"$i\" >".$row['ProductName']."</option>";
$i++;
}
?>

 

Make sure that the SQL matches the names in your database.

Link to comment
Share on other sites

My code

 

<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>

				<td width="55">product</td>
				<td width="762">
<select name="month">
<option value="">------</option>
<?PHP
include('adminconnect.php');
$query = "SELECT ProductName  FROM Products;
$result = mysql_query($query) or die (mysql_error());
$i=1;
while ($row = mysql_fetch_array($query))
{
echo "<option value=\"$i\" >".$row['ProductName']."</option>";
$i++;
}
?>
</select>
			  </td>
			</tr>
	  </table>

 

Is giving me the error

 

 

Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\Admin_files\sales_search.php on line 212

 

Line 212 is: echo "<option value=\"$i\" >".$row['ProductName']."</option>";

Link to comment
Share on other sites

Thanks again.

 

The list is still not being filled for some reason.

 

<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>

				<td width="55">product</td>
				<td width="762">
<select name="month">
<option value="">------</option>
<?PHP
include('adminconnect.php');
$query = "SELECT ProductName  FROM Products";
$result = mysql_query($query) or die (mysql_error());
$i=1;
while ($row = mysql_fetch_array($query))
{
echo "<option value=\"$i\" >".$row['ProductName']."</option>";
$i++;
}
?>
</select>
			  </td>
			</tr>
	  </table>

 

My sql for the db is:

 

CREATE TABLE `product` (

  `Producttype` varchar(4) collate latin1_general_ci default NULL,

  `ProductNo` decimal(7,0) NOT NULL default '0',

  `ProductName` varchar(80) collate latin1_general_ci default NULL,

  `Stockamount` decimal(5,0) default NULL,

  `Display` varchar(3) collate latin1_general_ci default NULL,

  `Description` varchar(10000) collate latin1_general_ci default NULL,

  `Price` decimal(6,2) default NULL,

  `Image` varchar(50) collate latin1_general_ci default NULL,

  `Image2` varchar(50) collate latin1_general_ci default NULL,

  PRIMARY KEY  (`ProductNo`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

 

 

 

Link to comment
Share on other sites

I just cant see why the box isnt filling up. The code looks fine to me and I'm not getting any errors. Its doing my head in!!

 

<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>

				<td width="55">product</td>
				<td width="762">
<select name="month">
<option value="">------</option>
<?PHP

include('adminconnect.php');
$query = "SELECT ProductName FROM Products";
$result = mysql_query($query) or die (mysql_error());
$i=1;
while ($row = mysql_fetch_array($query))
{
echo "<option value=\"$i\" >".$row['ProductName']."</option>";
$i++;
}
?>
</select>
			  </td>
			</tr>
	  </table>

 

 

Link to comment
Share on other sites

<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>

				<td width="55">product</td>
				<td width="762">
<select name="month">
<option value="">------</option>
<?PHP

include('adminconnect.php');
$query = "SELECT ProductName FROM Products";
$result = mysql_query($query) or die (mysql_error());
$i=1;
while ($row = mysql_fetch_array($query))
{
echo "<option value=".$i.">".$row['ProductName']."</option>";
$i++;
}
?>
</select>
			  </td>
			</tr>
	  </table>

 

try that

Link to comment
Share on other sites

My complete code now is:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin Page | sales</title>
<link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="../includes/wrapper.js"></script>
</head>
<body>
<div id="Box">

<div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../images/logo.gif" width="51" height="125" border="0" /></a></div>
<div id="contentBox">
<form>
<!-- logo start -->
<div id="container">
	<div class="padTop28"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>

<!-- logo finish -->



<!-- menu start -->
<div id="container">
			<div id="menu1">
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/start.php" class="black">Order</a></div>

		<div id="menu_space1"><!-- --></div>
		<div id="menu_on"><!-- --></div>
            <div id="menu_text_on"><a href="../admin_files/sales.php" class="black_on">Sales</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/list.php" class="black">Edit item</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>

		<div id="menu_text_off"><a href="../admin_files/sales.php" class="black">Postage fee</a></div>
		<div id="menu_space1"><!-- --></div>
            <div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../admin_files/adminreg.php" class="black">Add User</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../admin_files/add.php" class="black">Add Product</a></div>
		<div id="menu_space1"><!-- --></div>
	</div>

	<div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="dotted"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="menu2">

		<div id="menu_hide"><!-- --></div>
		<div id="menu_text_off" class="textWhite">order</div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_hide"><!-- --></div>
		<div id="menu_text_off"><a href="sales.php" class="black">Sales</a></div>
		<div id="menu_space2"><!-- --></div>
		<div id="menu_text_on"><a href="sales_search.php" class="black_on">Sales search</a></div>

		<div class="clr"><!-- --></div>
	</div>
	<div class="clr"><!-- --></div>
	<div class="padTop38"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- menu finish -->



<!-- top start -->

<div id="container">
	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="titleText">sales search</div>

	<div class="clr"><!-- --></div>
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- top finish -->



<!-- 1px space start -->
<div id="containerBg1">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- 1px space finish -->



<!-- data top start -->
<div id="containerBg3">
	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>

</div>
<div class="clr"><!-- --></div>
<!-- data top finish -->



<!-- data content start -->
<div id="containerBg4">

	<!-- data start -->
	<div class="padTop11"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div class="padTop1">

		<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>
				<td width="55">month</td>
				<td width="762">
<select name="month" class="000">
<option value="">------</option>
<option value="2006-06" >2006-06</option>

<option value="2006-05" >2006-05</option>
<option value="2006-04" >2006-04</option>
<option value="2006-03" >2006-03</option>
<option value="2006-02" >2006-02</option>
<option value="2006-01" >2006-01</option>
<option value="2005-12" >2005-12</option>

</select>
			  </td>
			</tr>
	  </table>
	</div>
	<div class="clr"><!-- --></div>
	<div class="padTop11"><!-- --></div>
	<div class="clr"><!-- --></div>
	<!-- data finish -->


	<!-- data start -->
	<div class="padTop1">
		<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>
				<td width="55">year</td>
				<td width="762">
<select name="year" class="">
<option value="">------</option>

<option value="2006" >2006</option>
<option value="2005" >2005</option>
</select>
			  </td>
			</tr>
	  </table>
	</div>
	<!-- data finish -->



	<!-- line start -->
	<div class="clr"><!-- --></div>
	<div class="padTop11"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="dottedIn"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="sales_text_and">and / or</div>
	<div id="dottedIn"><!-- --></div>

	<div class="clr"><!-- --></div>
	<div class="padTop11"><!-- --></div>
	<div class="clr"><!-- --></div>
	<!-- line finish -->


	<!-- data start -->
	<div class="padTop1">

<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="33"> </td>

				<td width="55">product</td>
				<td width="762">
<select name="month">
<option value="">------</option>
<?PHP

include('adminconnect.php');
$query = "SELECT ProductName FROM Products";
$result = mysql_query($query) or die (mysql_error());
$i=1;
while ($row = mysql_fetch_array($result))
{
echo "<option value=".$i.">".$row['ProductName']."</option>";
$i++;
}
?>
</select>
			  </td>
			</tr>
	  </table>

	</div>
	<div class="clr"><!-- --></div>
	<div class="padTop11"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="dottedIn"><!-- --></div>
	<div class="clr"><!-- --></div>
	<!-- data finish -->


	<!-- btn start -->
	<div class="padTop16"><!-- --></div>

	<div class="clr"><!-- --></div>
	<div id="btn"><a href="sales_search_result.php"><img src="../images/btn_search.gif" alt="search" width="73" height="23" border="0" /></a></div>
	<div class="clr"><!-- --></div>
	<div class="padTop16"><!-- --></div>
	<div class="clr"><!-- --></div>
	<!-- btn finish -->


</div>
<div class="clr"><!-- --></div>
<!-- data content finish -->




<!-- data btm start -->
<div id="containerBg3">
	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data btm finish -->



<!-- btm start -->
<div id="containerBg1">

	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div id="container">
	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div class="padTop16"><!-- --></div>

<div class="clr"><!-- --></div>
<!-- btm finish -->

</form>
</div>

</div>
</body>
</html>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.