How to add blank and or custom values to my array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kds08
Forum Newbie
Posts: 3
Joined: Fri Apr 25, 2008 6:08 am

How to add blank and or custom values to my array

Post 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>
mcmweb
Forum Newbie
Posts: 2
Joined: Fri Apr 25, 2008 7:17 am

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

Post by mcmweb »

Why do you need the blank array?
Last edited by onion2k on Fri Apr 25, 2008 8:58 am, edited 1 time in total.
Reason: Adding a link to your site with no good reason is spamming. Don't do it again.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

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

Post 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');
 
kds08
Forum Newbie
Posts: 3
Joined: Fri Apr 25, 2008 6:08 am

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

Post 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.
kds08
Forum Newbie
Posts: 3
Joined: Fri Apr 25, 2008 6:08 am

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

Post by kds08 »

anyone?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

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

Post by aceconcepts »

Post your new code.
Post Reply