Jump to content

Recommended Posts

I have a very simple script set up that pulls data from a database and is output using this 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:

2250

In stock.

Product One

2251

In stock. On order.

Product Two

2252

Out of stock. On order.

Product Three

2253

Out of stock.

Product Four

Link to comment
https://forums.phpfreaks.com/topic/186358-filtering-an-array-based-on-value/
Share on other sites

Beautiful, thank you very much for the quick reply.

 

There is also a 'date' column which stores the date at which the field was added to the database. Because the script is run daily, there are multiple occurrences of each 'sku' with different statuses. How would I only display the most recent occurrence of each record?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.