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
jonnyfortis
Forum Contributor
Posts: 462 Joined: Tue Jan 10, 2012 6:05 am
Post
by jonnyfortis » Mon Feb 17, 2014 9:49 am
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; ?>
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Mon Feb 17, 2014 9:54 am
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
Post
by jonnyfortis » Mon Feb 17, 2014 10:26 am
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
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Mon Feb 17, 2014 10:30 am
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
Post
by jonnyfortis » Mon Feb 17, 2014 10:33 am
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
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Mon Feb 17, 2014 10:40 am
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
Post
by jonnyfortis » Mon Feb 17, 2014 10:56 am
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
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Mon Feb 17, 2014 11:08 am
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
Post
by jonnyfortis » Mon Feb 17, 2014 11:37 am
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?
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Mon Feb 17, 2014 11:53 am
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
Post
by jonnyfortis » Mon Feb 17, 2014 1:47 pm
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.
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Mon Feb 17, 2014 1:53 pm
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
Post
by jonnyfortis » Mon Feb 17, 2014 2:00 pm
Celauran wrote: I had a typo in there; forgot the closing > on option tag.
yes found it. thanks for you help.