Page 1 of 1

How to add blank and or custom values to my array

Posted: Fri Apr 25, 2008 6:12 am
by kds08
I’m trying to design an inventory system and im running into problems with my code.
I have a page where I want to add a number of parts to a order. However, sometimes we may use 1 part, sometimes 2, sometimes three, or sometimes none at all. I am pulling the data I need out of the database, but, how do I add a additional array that is blank or maybe one that saids “Empty” when they user doenst need to add a part.
Or a custom option that is coded right into the php page. (prefer to put it at the top of the option list)
Here is my code:



include 'include/connect.php';

Part 1:<select size="1" name="part1">
<?
$opt = @mysql_query("SELECT * FROM inventory2 WHERE part_type='5' and availability>'0'");
if(@mysql_num_rows($opt) > 0){
while($opt_desc = @mysql_fetch_array($opt)){
?>
<option value="<?php echo $opt_desc[1] ?>"><? echo $opt_desc[2]; ?> - <? echo $opt_desc[4]; ?></option>
<? }} ?>
</select>


Part 2:<select size="1" name="part2">
<?
$opt = @mysql_query("SELECT * FROM inventory2 WHERE part_type='5' and availability>'0'");
if(@mysql_num_rows($opt) > 0){
while($opt_desc = @mysql_fetch_array($opt)){
?>
<option value="<?php echo $opt_desc[1] ?>"><? echo $opt_desc[2]; ?> - <? echo $opt_desc[4]; ?></option>
<? }} ?>
</select>


Part 3:<select size="1" name="part3">
<?
$opt = @mysql_query("SELECT * FROM inventory2 WHERE part_type='5' and availability>'0'");
if(@mysql_num_rows($opt) > 0){
while($opt_desc = @mysql_fetch_array($opt)){
?>
<option value="<?php echo $opt_desc[1] ?>"><? echo $opt_desc[2]; ?> - <? echo $opt_desc[4]; ?></option>
<? }} ?>
</select>

Re: How to add blank and or custom values to my array

Posted: Fri Apr 25, 2008 7:20 am
by mcmweb
Why do you need the blank array?

Re: How to add blank and or custom values to my array

Posted: Fri Apr 25, 2008 7:40 am
by aceconcepts
To setup a single array:

Code: Select all

 
$myArray=array('part'=>'empty');
 
To append to an array:

Code: Select all

 
$myArray[]=array('part'=>'empty');
 

Re: How to add blank and or custom values to my array

Posted: Sat Apr 26, 2008 2:00 pm
by kds08
It don’t seem to work. Here is a sample of what it does before I added the code you provided so you can visualize what I am trying to do.
Maybe I wasn’t adding the code to the correct spot or something.

http://www.codetest.info/sandbox/add.php

I’m still working on it displaying the correct seletion box as well once it brings you to the part that has all the data plugged in from the database. Im not sure how to do that either. It places the info in the database, but just not showing the option choice.

Re: How to add blank and or custom values to my array

Posted: Tue Apr 29, 2008 9:27 pm
by kds08
anyone?

Re: How to add blank and or custom values to my array

Posted: Wed Apr 30, 2008 3:28 am
by aceconcepts
Post your new code.