• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

add select input field

add a select input field that has the value 'quantity' by default
other choices are
1
2
3


I think something like this
echo '<td>quantity:<input type="select" id ="quantity" name = "quantity['.$p['quantity'].']" value="'.$p['quantity']"'></td>
<?php
//connect to db first
//...
require_once('inc/common.php');

if( isset($_POST) && !empty($_POST) )
{
 foreach($_POST['productid'] as $id =>$v){
   $productid=$_POST['productid'][$id];
   $title=$_POST['title'][$id];
   $internalsku=$_POST['internalsku'][$id];
   dbquery("UPDATE products SET title = '$title',internalsku='$internalsku' WHERE productid = '$productid'");
 }
 echo "Updated";
 exit;
}
echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
echo '<table>'; // this is echoing html //
$sql=dbquery("select * from products where folderid=120 order by productid desc"); // this selecting all products from db //
foreach ($sql as $p){ //unsure of this i think hes changeing sql to p//
echo '<tr><td>productid:<input type="text" id="productid" name="productid[' . $p['productid'] . ']" value="'.$p['productid'].'" style="width:500px;">'; // now lists all data in a table by product id//
echo '<td>title:<input type="text" id="title" name="title['.$p['productid'].']" value="'.$p['title'].'" style="width:500px;"></tr>';
echo '<td>title:<input type="text" id="internalsku" name="internalsku['.$p['productid'].']" value="'.$p['internalsku'].'" style="width:500px;"></tr>';
} // now lists all products by title //
echo '</table>'; // end of html table//
echo "<div><input type='submit' name='trigger' value='Submit' /></div>";
echo "</form>";
?>

Open in new window

0
rgb192
Asked:
rgb192
  • 2
  • 2
1 Solution
 
Om PrakashCommented:
Try
echo 'quantity:<select id ="quantity" name = "quantity"><option>quantity</option><option>1</option><option>2</option><option>3</option></select>'
0
 
Om PrakashCommented:
using loop
<?php
echo "<select name=quantity>";
echo "<option value=". "0" .">Quantity</option>";
for($i=1; $i <= 3; $i++)   echo "<option value=". $i .">" . $i . "</option>";
echo "</select>";// Closing of list box
?>

Open in new window

0
 
rgb192Author Commented:
that makes select fields

look exactly like

" . $i . "

with NO numbers
0
 
hieloCommented:

<?php
//connect to db first
//...
require_once('inc/common.php');

if( isset($_POST) && !empty($_POST) )
{
 foreach($_POST['productid'] as $id =>$v){
   $productid=$_POST['productid'][$id];
   $title=$_POST['title'][$id];
   $internalsku=$_POST['internalsku'][$id];
   dbquery("UPDATE products SET title = '$title',internalsku='$internalsku' WHERE productid = '$productid'");
 }
 echo "Updated";
 exit;
}
echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
echo '<table>'; // this is echoing html //
$sql=dbquery("select * from products where folderid=120 order by productid desc"); // this selecting all products from db //
foreach ($sql as $p){ //unsure of this i think hes changeing sql to p//
	echo '<tr><td>productid:<input type="text" id="productid" name="productid[' . $p['productid'] . ']" value="'.$p['productid'].'" style="width:500px;">'; // now lists all data in a table by product id//
	echo '<td>title:<input type="text" id="title" name="title['.$p['productid'].']" value="'.$p['title'].'" style="width:500px;"></tr>';
	echo '<td>title:<input type="text" id="internalsku" name="internalsku['.$p['productid'].']" value="'.$p['internalsku'].'" style="width:500px;"></tr>';
	echo '<select name="quantity">';
	for($i=1; $i<=3; ++$i)
	{
		$selected = ($i==$p['quantity'] ? " selected='selected' " : "");
		echo "<option {$selected} value='{$i}'>{$i}</option>";
	}
	echo '</select>';
} // now lists all products by title //
echo '</table>'; // end of html table//
echo "<div><input type='submit' name='trigger' value='Submit' /></div>";
echo "</form>";
?>

Open in new window

0
 
rgb192Author Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now