I want to see how I can use !in_array.
I have this code, but it doesn't work:
while ($row = mysql_fetch_assoc($result)) {
if (!in_array($row['item'], $output)) {
$output[] = $row;
}
}
print(json_encode($output)); // need all rows, not just ['item']
Yes, I knowI am using older mysql and the code is not very "safe". Just want to know about to check if an item is in an array or not. IF it is not, I want it to store. If it is, I want the loop to skip...
EDIT: This is an additional idea:
$items[] = "";
while ($row = mysql_fetch_assoc($result)) {
$item[] = $row['item'];
if (!in_array($row['item'], $items)) {
$output[] = $row;
}
}
print(json_encode($output));
This code puts all items in the array even duplicates; I'm doing this to prevent dulicates
My SQL:
$result = mysql_query("
SELECT b.item, a.rate_id, a.review, c.category, u.username
FROM comments a
INNER JOIN items b
ON a.item_id = b.items_id
INNER JOIN master_cat c
ON c.cat_id = b.cat_id
INNER JOIN users AS u
ON u.user_id = a.user_id
ORDER BY rate_id DESC LIMIT 15;");
$outputarray seems to be filled with rows from the database, why not just change the query to include only distinctitemcolumn values?