Filtering an Array Based on Value


Posted on 16th Feb 2014 07:03 pm by admin

I have a very simple script set up that pulls data from a database and is output using this code:

Code: Print "<table border cellpadding=3>";
Print "<th>sku</th><th>status</th><th>name</th>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<td>".$info['sku'] . "</td> ";
Print "<td>".$info['status'] . "</td> ";
Print "<td>".$info['name'] . " </td></tr>";
}
Print "</table>";
However, I would like to only output rows that meet certain criteria. More specifically, I only want to show rows in which the 'status' field contains the text value "Out of stock" at any position within the field. (e.g. some fields say "Out of stock. On order.")

Any help with this will be greatly appreciated.

And here's a sample of what the table output currently looks like:
2250In stock.Product One2251In stock. On order.Product Two2252Out of stock. On order.Product Three2253Out of stock.Product Four

No comments posted yet

Your Answer:

Login to answer
285 Like 42 Dislike
Previous forums Next forums
Other forums

exclude characters from counting?
Hello, I wanted to ask if you have a string like:
Code: $my_s='ASRGREGTGTR----REGREGRE+++RRRRRR..

Error in write byte array into document in SM58
Hi Gurus,

Getting the following error status in Transactional RFC (SM58) ..... *Error i

batch file not building to webapps folder
Hello. I just started running Vista :P and can't seem to get my projects deployed. I found out how

utf8_general_ci error ??
I have all kinds of data to be inserted in database table

//I am getting this error

Yo

Error In Syntax
I got this error:

Code: Parse error: syntax error, unexpected '>' in /home/bucket/publ

PHP/Database issue
My friend is helping me make a database where you go to a certain webpage of my site and the page wi

cURL proxy
Okay here is the thing... i know how to add proxys

Code: curl_setopt($ch, CURLOPT_PROXYTYPE,

my login script page is not working on remote computers
hi my login is working on my computer, but when i tried 2 computers from 2 different locations, they

disabling a button server-side then re-enabling client-side breaks button postback
I have a tabbed container and a button (not in the container) on a page. If the first tab is selecte

whats wrong with my code please help!!!
this is the error


Warning: mysql_close(): supplied argument is not a valid MySQL-Link res

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash