swib30 Posted December 26, 2009 Share Posted December 26, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/186358-filtering-an-array-based-on-value/ Share on other sites More sharing options...
.josh Posted December 26, 2009 Share Posted December 26, 2009 select column from table where column not like '%out of stock%' Quote Link to comment https://forums.phpfreaks.com/topic/186358-filtering-an-array-based-on-value/#findComment-984117 Share on other sites More sharing options...
swib30 Posted December 26, 2009 Author Share Posted December 26, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/186358-filtering-an-array-based-on-value/#findComment-984124 Share on other sites More sharing options...
trq Posted December 26, 2009 Share Posted December 26, 2009 SELECT DISTINCT sku, status, name WHERE status NOT LIKE %out of stock% ORDER BY datefld DESC Quote Link to comment https://forums.phpfreaks.com/topic/186358-filtering-an-array-based-on-value/#findComment-984130 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.