First of all, i'd like to excuse if this question has already been answered, but I don't know keywords to search for it.. (it's a though question in my head, maybe it isn't though at all.. i don't know..)
Anyway, this is my problem:
I have 2 tables, let's call them `ToDo` and `Done`.
Bot tables have more than 10k values, of course, `ToDo` has more values than `Done`, but let's keep it at 10k.
Now, to query and requery those tables time after time to solve my troubles, seem like a (too much) immense data load on my database, So I've decided to query them just once, and drop the data inside an Array, using the following PHP Code:
Code: Select all
<?php
function QueryIntoArray($query){
settype($retval,"array");
$result=MySQL_Query($query);
if(!$result){
print "Query Failed";
}
for($i=0;$i<MySQL_Num_Rows($result);$i++){
for($j=0;$j<MySQL_Num_Fields($result);$j++){
$retval[$i][MySQL_Field_Name($result,$j)] = MySQL_Result($result,$i,MySQL_Field_Name($result,$j));
}//end inner loop
}//end outer loop
return $retval;
}//end function
?>
Now my problem:
I have a field, called `Tag`, this field can differ from both tables
e.g. Table `ToDo` has the following values:
100
133
910
9320
14
10
Table `Done` has this values:
100
133
20
14
10
Now, I wish to create a function which checks both arrays, to find the differences and outputs this:
100
133
14
10
910
9320
20
Color meanings: Green = In Both Tables, Blue = Only in `ToDo` Table, Red = Only in `Done` table..
I hope I make sense till now..
I know of the function In_Array($needle,$haystack), but if I use a For Loop
Code: Select all
for($i=0;$i<count($X);$i++){
for($c=0;$c<count($Y);$c++){
if(in_array($Y[$i]["tag"],$X["tag"],false)){
echo "true <br />";
}else{
echo "false <br />";
}
}
}
Then, in the second, I loop trough $Y (array of `Done`)
to see if the tag at which I am on $X, is available in $Y, and the other way around..
but: it gives me nothing at all, so I must do something wrong.. right?
Can anyone point me into a direction.. or at least tell me what I'm doing wrong?
and please, don't mind asking for a better description of my problem.. I've tried my best now, but it might be non-suited..
Yt, Eowyne