Democrazy
09-12-2011, 11:42 AM
I have a MySQL table called "products":
+------+-------+-------+-------+
| id | sizes | sizem | sizel |
+------+-------+-------+-------+
| 1 | 2 | 0 | 1 |
| 2 | 3 | 1 | 0 |
+------+-------+-------+-------+
What I am wanting to know is if I can make PHP print a value from it, but only if it is not a zero.. something like:
$sizeL = (table(products)id1.sizel);
if (table(products)id1.sizel == "0") {echo "";} else {echo "$sizeL";}
Yeah I know the above code is far from beeing valid, but is the best I could come up with. heh :)
djm0219
09-12-2011, 11:54 AM
Let SQL do the work and only select values from the column you are interested in if they have a value that is not zero. Then all you have to do with PHP is loop through the results and echo/print them.
SELECT `id` FROM `products` WHERE `sizel` != 0
Democrazy
09-12-2011, 12:00 PM
Sure, Dave, but what I am going to do is have:
Size S: 1
Size M: 2
Size L: 3
... am I correct in assuming that using the code you said, would produce this for a size M if it were 0?
Size S: 1
Size M:
Size L: 3
If so, thats why I want to echo the product size also, so if a product size does equal 0, then there is not going to be a product size with no number next to it, as can be seen above with size M.
:D :D
Democrazy
09-12-2011, 12:05 PM
Ah, I have left that out in my original post:
$sizeL = (table(products)id1.sizel);
if (table(products)id1.sizel == "0") {echo "";} else {echo "Size L: $sizeL";}
Democrazy
09-12-2011, 12:14 PM
Oh God, I have totally botched this post!
I will start over.
I have a MySQL table called "products":
+------+-------+-------+-------+
| id | sizes | sizem | sizel |
+------+-------+-------+-------+
| 1 | 3 | 2 | 2 |
+------+-------+-------+-------+
What I want to do is produce the following on a webpage:
Size S: 3
Size M: 2
Size L: 2
Using Size M for an example, to achieve this, I am thinking of code that would go along the lines of something like this:
$sizeM = (table(products)id1.sizem);
if ($SizeM == "0") {echo "";} else {echo "Size M: $sizeM";}
Just for example that Size M (sizem) in my MySQL database equaled 0, then the webpage would render like this:
Size S: 3
Size L: 2
How would I write that in PHP?
Inigoesdr
09-12-2011, 05:30 PM
Closing this since it's answered in your other thread.