Forum Moderators: coopster
I have some working code:
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($row['itemstatus'] == "1") {$avail='<div id="buttons"><p>
<a href="buyform.php?item='.$row['item'].'&class='.$class.'&desc=' .$row['itemname'].'&price='.$row['itemprice'].'" target="_blank">BUY</a></p>
<p><a href="#" onclick="sendAnnotatedMailTo(\'sales\',\'mcdonoughfineart\',\'com\','. '\''.$row['itemname'].' inquiry\');">Inquire</a></p></div>'; $row_style="stock";}
else {$avail="HOLD"; $row_style="holditem";}
Notice the test on 'itemstatus'.
Now I've decided that I need 3 states for that variable: Available, HOLD, and SOLD. (1,0,2).
After this IF statement is resolved the rest of the WHERE loop builds a table row for display. How do I make the function SKIP building the row when status of the item is SOLD?
Thanks in advance!
John
[edited by: jatar_k at 6:59 pm (utc) on Feb. 28, 2004]
[edit reason] fixed sidescroll [/edit]
If zero, the row is built using a CSS class that displays it differently and the word HOLD is printed where the buttons would be.
If 1, the table row is built and buttons are included to allow a user to buy or inquire about the item.
Should I post or attach the whole code?
John
How does that stop it from completing the where loop and building the table row?
I don't get the question.
You want to complete the whole loop I would think. Actually i was a little confused there. You don't need the check for!=2 at all just the addition of else if instead of plain if.
As it stood in your original you tested for 1 and did something special for it and everything else was processed in your else.
If you want to process 1 one way
process 0 another way
and not process 2
then you need to explicitly handle 1 and 0 and not do anything if you have a 2.
therefore
if ($row['itemstatus'] == "1") {
// do stuff for AVAILABLE status
} else if ($row['itemstatus'] == "0") {
// do stuff for HOLD status
}
and we ignored SOLD altogether
The current code tests for 0 or 1. If 1, it builds buttons (you see that in the code I posted), if Zero it sets the button variable to the word HOLD which is echoed into the HTML.
After the tests, the where loop builds the table rows. Currently it builds the table row either with the buttons (itemstatus=1) or without (itemstatus=0).
I want to NOT BUILD A ROW if the status is SOLD (itemstatus=2). - basically just increment the loop.
I think I might have to enclose the table building part in another IF.
I thought about doing:
while($row = mysql_fetch_array($result, MYSQL_ASSOC) AND $row['itemstatus']!= "2")
John
Either that, or you could enclose the button building and the table building in an IF. Something like:
if ($row['itemstatus']!="2") {
.
.
all the code you have in the while
}
So if it's SOLD, then the loop will just be incremented. I think that's better than just putting the table building in an IF, because there will be less checking to be done during parsing - if it's a SOLD, then the loop increments right away, without first going through two IF's to see if a button has to be built.
Something like:
$query = "SELECT * FROM your_table WHERE itemstatus = 'test1' OR itemstatus = 'test2'";
No need to pull data that you aren't going to use. Save on resource use both in the DB access and in the running of the script.
WBF