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>";
Did you know?Explore Trending and Topic pages for more stories like this.
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

PHP IMAGE UPLOAD SCRIPT
Hi for the last week i have been looking for scripts that will upload a photo to a certain folder wh

Binding 2 UDP sockets on same port, connected to different destinations, 1 receives
Hello,
My application wants to send/recv data to 2 different UDP ports on a remote computer, us

Adding post count
How would I make it so everytime someone clicks submit on my form, their row in the database for the

Help With editting and deleting form
So look at this image :

http://img194.imageshack.us/img194/8272/snapshot5f.png
This table

Passing Variables
What I'm wanting to do is when the user clicks on Arenas it will know the name of the country it's w

Need help making a script that moves data into acrhive table
Hi,

I'm kinda new to php/mysql

And i wrote a simple script to store sales lead for a b

PHP SUBMIT
Code: <input name="doLogin" type="image" src="images/loginsubmit.jpg

Procedure with variable number of columns
Hi, I have a procedure that looks like this:

PROCEDURE PROC(p_cursor OUT sys_refcurso

Switch letters in message (basic cryptology)...
I am trying to switch letters around in a message for an application on my site (see here). The prob

EU VAT Package 2010
Does any one know whether SAP will be developing new reporting functionality due the new VAT rules t

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