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

restricting another login once you logout
Hello,

how can I restrict a page from login authenticating against info in a MySQL DB for a s

how make 2 column in table with data tybe long row
hi every one

I want make in my table 2 column with data tybe long raw

how thi

Month String to Numeric?
Hi guys,

Given a month as a string, is there a simple way to find the numeric representation

Count Session and Trigger Events
I am New in PHP, seeking a method to count logged users by counting the sessions or any …, is

How can you detect variable string in a massive string?
Ok guys, i need some help with this one.

I am going to be getting a large string, like 10-20

help with Get_
ok some how this is not working i am not sure what i am doing wrong here but what this does is when

Create or replace package is ending ORA-21700
Database 9.2.0., patch 8 (9.2.0.8.0).
I trying run
create or replace package ....etc.

Reg Ex
Im trying to search for the string: srv_9 (Dead ???)

I thought to use preg_match, however I d

Help with PHP Email Script
Hi guys,

I'm a newbie to php and need help with the script below:

At the moment when I

Warning message
I've put a website that I was doing live and I'm getting this warning message when I try to add a ne

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