Re: Excluding records from repeat region in PHP



duncan.lovett@xxxxxxxxxxx wrote:
[snip]
GOAL
----
The way I am planning to get around this problem is keep the 'Hidden'
table, create TWO recordsets on a page - one, rsFetchProducts, a
"SELECT * FROM Products" and the other, rsFetchHiddenProducts, "SELECT
Product_ID from HiddenProducts where User_ID = 'users id number'".

I then apply a repeat region to rsFetchProducts to list all data from
the recordset.

******************
What I need to do next is to filter this repeat region with PHP,
basically saying - if any of the Product_ID(s) in rsFetchProducts is
equal to any of the Product_ID(s) in rsFetchHiddenProducts, DON'T
include them in the repeat region.
******************

This must be possible, but by background on PHP isn't too great, I know
I need an if condition in the repeat region, but am not sure if I need
to filter directly from the recordset or pop it into an array first and
then filter.
[snip]

Try something like this:

<?php
$link = mysql_connect($mysql_address, $mysql_user, $mysql_password) or die("Could not connect : " . mysql_error());
mysql_select_db($mysql_database) or die("Could not select database");
$query = "SELECT Product_ID FROM HiddenProducts WHERE User_ID = 'users id number'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
//Fetch results as associative array.
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
//Saving user's hidden ids in array $hidden_ids.
$hidden_ids[] = $row[Product_ID];
}
$query = "SELECT * FROM Products";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
//Fetch results as associative array.
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
//Looping over $hidden_ids to check if the user is allowed to see the product
foreach($hidden_ids as $value) {
if($row[Product_ID] == $value) {
$allowed = "no";
} else {
if($allowed != "no") {
$allowed = "yes";
}
}
}
if($allowed == "yes") {
//***********************************************
//* Place the code to display the product here. *
//***********************************************
}
}
?>


Zilla

--
HUSK: Fjern de store bogstaver i
e-mailen for at skrive til mig

REMEMBER: Remove the capital letters
in my e-mail to write to me.
.