if value == value 1 or value 2

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
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

if value == value 1 or value 2

Post by jonnyfortis »

i have 3 product code 958, 959 and 960

if either of the first are chosen i want to show one input type. if neither of these are shown i want another input type to show

have tried
<? if ($row_rsSize['StockID'] == '958' or '959'):

but obviously the or is incorrect

Code: Select all

<? if ($row_rsSize['StockID'] == '958' or '959'):
		?>
              <select name="Quantity[]" value="<?php echo $XCart_Quantity = ${$XCName}["contents"][3][$XCart__i]; ?>">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
              </select>
              (max: 3 caps per order)
<?php endif; ?>
<? if ($row_rsSize['StockID'] !== '958' or '959'):
		?>
              <input name="Quantity[]" type="text" value="<?php echo $XCart_Quantity = ${$XCName}["contents"][3][$XCart__i]; ?>" size="2" maxlength="2" />
<?php endif; ?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: if value == value 1 or value 2

Post by Celauran »

Code: Select all

if ($row_rsSize['StockID'] == '958' || $row_rsSize['StockID'] == '959')
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: if value == value 1 or value 2

Post by jonnyfortis »

Celauran wrote:

Code: Select all

if ($row_rsSize['StockID'] == '958' || $row_rsSize['StockID'] == '959')
thats great thanks..however what seems to be happening and i dont know why is i am getting an extra text input

Code: Select all

              <? if ($row_rsSize['StockID'] == '958' || $row_rsSize['StockID'] == '959'):
		?>
              <select name="Quantity[]" value="<?php echo $XCart_Quantity = ${$XCName}["contents"][3][$XCart__i]; ?>">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
              </select>
              (max: 3 caps per order)
<?php endif; ?>
<? if ($row_rsSize['StockID'] !== '958' || $row_rsSize['StockID'] == '959'):
		?>
              <input name="Quantity[]" type="text" value="<?php echo $XCart_Quantity = ${$XCName}["contents"][3][$XCart__i]; ?>" size="2" maxlength="2" />
<?php endif; ?>  
there is another text box appearing directly after "(max: 3 caps per order)"
then the correct text box is showing if stock id 960 is showing
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: if value == value 1 or value 2

Post by Celauran »

Code: Select all

if ($row_rsSize['StockID'] !== '958' || $row_rsSize['StockID'] == '959')
Are you sure this is what you meant? If it's not 958 or if it is 959?
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: if value == value 1 or value 2

Post by jonnyfortis »

Celauran wrote:

Code: Select all

if ($row_rsSize['StockID'] !== '958' || $row_rsSize['StockID'] == '959')
Are you sure this is what you meant? If it's not 958 or if it is 959?
sorry i meant if not either 958 or 959
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: if value == value 1 or value 2

Post by Celauran »

So

Code: Select all

if ($row_rsSize['StockID'] != '958' && $row_rsSize['StockID'] != '959')
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: if value == value 1 or value 2

Post by jonnyfortis »

brilliant. that done it the only thing that is happening now is when i confirm the select quantity as for example as 2 that the menu reverts back to 1 when i confirm. it isnt holding the value.
thanks
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: if value == value 1 or value 2

Post by Celauran »

For that, you need to add selected="selected" to the selected entry.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: if value == value 1 or value 2

Post by jonnyfortis »

Celauran wrote:For that, you need to add selected="selected" to the selected entry.
sorry i sort of get what you mean but where does it go?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: if value == value 1 or value 2

Post by Celauran »

Try something like this

Code: Select all

<?php if ($row_rsSize['StockID'] == '958' || $row_rsSize['StockID'] == '959'): ?>
	<?php $selected = ${$XCName}["contents"][3][$XCart__i]; ?>
	<select name="Quantity[]">
		<?php for ($i = 1; $i <= 3; $i++): ?>
		<option value="<?= $i; ?>" <?= $selected == $i ? 'selected="selected"' : ''; ?>><?= $i; ?></option>
		<?php endfor; ?>
	</select>
	(max: 3 caps per order)
<?php endif; ?>
Last edited by Celauran on Mon Feb 17, 2014 1:53 pm, edited 1 time in total.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: if value == value 1 or value 2

Post by jonnyfortis »

Celauran wrote:Try something like this

Code: Select all

<?php if ($row_rsSize['StockID'] == '958' || $row_rsSize['StockID'] == '959'): ?>
	<?php $selected = ${$XCName}["contents"][3][$XCart__i]; ?>
	<select name="Quantity[]">
		<?php for ($i = 1; $i <= 3; $i++): ?>
		<option value="<?= $i; ?>" <?= $selected == $i ? 'selected="selected"' : ''; ?><?= $i; ?></option>
		<?php endfor; ?>
	</select>
	(max: 3 caps per order)
<?php endif; ?>
brilliant thanks just added the end value tag >

Code: Select all

<option value="<?= $i; ?>" <?= $selected == $i ? 'selected="selected"' : ''; ?>><?= $i; ?></option>
and worked
thanks again
Last edited by jonnyfortis on Mon Feb 17, 2014 1:54 pm, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: if value == value 1 or value 2

Post by Celauran »

I had a typo in there; forgot the closing > on option tag.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: if value == value 1 or value 2

Post by jonnyfortis »

Celauran wrote:I had a typo in there; forgot the closing > on option tag.
yes found it. thanks for you help.
Post Reply