0

I have this code:

foreach( $_POST[ 'count' ] as $textBoxIndex => $textBoxValue ) {

echo '<br />Textbox ' . $textBoxIndex . ' has value [' . $textBoxValue . ']';

}

This loops through a series of text boxes with have been created with this:

<while($rowequipment = mysql_fetch_assoc($sqlequipment)) {
echo '<input type="checkbox" name="equipment[]"value="'.$rowequipment['equipmentid'].'"/>
<input type="text" name="count[]" id="count[]" size="3" value=""/>'
.$rowequipment['description']."<br />";
}

The purpose here is to try and create a system by which the user can input how many of each peice of equipment they want and store it in the database.

However the problem is that the first peice of code is going through the blank textboxes as well and returning null pieces of data which i cannot insert into the database.

My question is how would i use the first peice of code but not print out the text boxes which have no value?

Thanks.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Rynkadink
0

Just test if the value is empty or null with empty() function.

foreach( $_POST[ 'count' ] as $textBoxIndex => $textBoxValue ) {
    if( !empty($textBoxValue) )
        echo '<br />Textbox ' . $textBoxIndex . ' has value [' . $textBoxValue . ']';
}

Cheers!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.