Forum Moderators: coopster
ie. id1,id2,id3 etc
I am using a for each statement to match these ids from a table
foreach ($array as $id)
{
select * from table where ID='$id'
print row from table
}
Anyway this all works fine BUT I want to then return all the rows that do NOT have that ID in them - not sure how to go about this.
I was thinking I could do select * from table where ID!='$id' but how?
Obviously I need some way to spit out everything that IS NOT in the array, maybe if I select all from the table and then do a while id exits in row print row, if id isn't in row print id does not exist in row?
$query = "SELECT * FROM table;
$result = mysql_query( $query );
do {
for( $i = 0; $i < array_size; $i++ ) {
if ( $row["id"]!= array[$i]["id"] )
echo "some stuff";
}
reset( array );} while ( $row = mysql_fetch_assoc( $result ) );
Basically do one query and iterate through the array looking for matches.
Extra thought:
Because this would be quite aggressive on large data sets, if $id was numeric, I think I'd be tempted to add a little more intelligence to the inner loop:
Sort the array["id"] by $id.
Then the for loop could:
for( $i = 0; $row["id"] > array[$i]["id"] && $i < array_size; $i++ ) {
if ( $row["id"]!= array[$i]["id"] )
echo "some stuff";
}
asp
Thanks in the end I did something fairly similar...
select everything from table then
$levels = explode(",", $userlevel);
$z=0;
while ( $z<count($levels)) {
if ($levels[$z]=="$table_userlev") {
"Do some stuff"
$test=1;
}
++$z
if ($test!=1){
"do some other stuff"
}
else { $test=2; }
appreciate any comments flaws, better ways to do this?
All i want to do is output what the user can access and what they can't