Page 1 of 1

Array_intersect or sql query?

Posted: Thu Jul 07, 2005 4:34 pm
by ron_j_m
Im trying to find the values in two different database tables that are the same.
In 1 row there are about 20,000 entries. In the other there are over 40,000 and probably more later.
I have been trying to use an sql query such as

Code: Select all

$query = mysql_query(&quote;SELECT names.id AS id1, names.name AS name1, dictionary.id AS id2, dictionary.word AS name2 FROM names, dictionary WHERE names.name = dictionary.word&quote;);
This seems to work ok with smaller rows but when I try it on larger rows it seems to timeout.

Because of that I have been trying to use array_intersect instead.
Im not sure how well either one of these will work with such large arrays.

I havent been able to get array_intersect to work after using mysql_fetch_array to get the data from the database. Ive been looking around and have yet to find any examples of how this is done so I have been playing with this for about a week now and getting no where.
Any Ideas...

Here is kind of what Ive been doing (1 of about a million versions any way....Hope someone can help.

Code: Select all

<?
include 'includes.inc.php';

mysql_connect ("$hostname", "$username", "$password") or die ('I cannot connect to the database because: ' . mysql_error());
@mysql_select_db ("$database") or die( "Unable to select database");

$result = mysql_query("SELECT test3.id AS id1, test3.name AS name1, dictionary.id AS id2, dictionary.word AS name2 FROM test3, dictionary");

while ($row = mysql_fetch_array($result)) {
 
   $emulated_join = array_intersect($name1, $name2);
      
}
mysql_free_result($result);
?>
ive also tried something like this and get argumant 1 is not an array arror

Code: Select all

$result1 = mysql_query("SELECT test3.name FROM test3")or die ('I cannot connect to the database1 because: ' . mysql_error());
$result2 = mysql_query("SELECT dictionary.word FROM dictionary")or die ('I cannot connect to the database1 because: ' . mysql_error());


$emulated_join = array_intersect($result1, $result2);

print ("<pre>");
   print_r ($emulated_join); 
   print ("</pre>");
Any Ideas..
Thanks
Ron

Posted: Thu Jul 07, 2005 6:40 pm
by timvw
A real sql-dbms would allow you to use "INTERSECT"... Well, at MySQL they are planning to implement it.... sometime....


The following query might work a little faster... Otherwise try http://www.php.net/set_time_limit

Code: Select all

SELECT names.*
FROM names
INNER JOIN dictionary ON names.name=dictionary.word
I don't think that using php's array function will result in something that is faster...

Posted: Thu Jul 07, 2005 10:53 pm
by ron_j_m
Thanks for the reply. The query works well. I think my main problem was I did not have indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ronlt1 = mysql_query("SELECT dict.word1 FROM dict&quote;);
$result2 = mysql_query(&quote;SELECT dict2.word2 FROM dict2&quote;);
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print (&quote;&lt;pre&gt;&quote;);
print_r ($emulated_join);
print (&quote;&lt;/pre&gt;&quote;)


Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ron
One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Anyy Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>&e;);
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db dae indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query(&quote;SELECT dict.word1 FROM dict&quote;);
$result2 = mysql_query(&quote;SELECT dict2.word2 FROM dict2&quote;);
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print (&quly. The query works well. I think my main problem was I did not have indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array. 
Heres what I have and it returns an empty array. 
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Rons right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2&quote;);
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print (&quote;&lt;pre&am cant get it to work properly while using mysql_fetch_array. 
Heres what I have and it returns an empty array. 
Any Ideas.

Code: Select all

$result1 = mysql_query(&quote;SELECT dict.word1 FROM dict&quote;);
$result2 = mysql_query(&quote;SELECT dict2.word2 FROM dict2&quote;);
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print (&quote;&lt;pre&gt;&quote;);
print_r ($emulated_join);
print (&it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array. 
Heres what I have and it returns an empty array. 
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an lls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using ct");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")


Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ronlt1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")


Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Roncolums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready establisheoblem was I did not have indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
ion on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db dataeres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fiquote;);
print_r ($emulated_join);
print ("</pre>")


Using an allready established array emulatedjoin works fine
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2&quotein problem was I did not have indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array. 
Heres what I have and it returns an empty array. 
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict&quote;);
$result2 = mysql_query(&quote;SELECT dict2.word2 FROM dict2&quote;);
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print (&quote;&lt;pre&gt;&quote;);
print_r ($emulated_join);
print (&quote;&lt;/pre&gt;&quote;)
[ly while using mysql_fetch_array. 
Heres what I have and it returns an empty array. 
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query(&quote;SELECT dict2.word2 FROM dict2&quote;);
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print (&quote;&lt;pre&gt;&quote;);
print_r ($emulated_nt get it to work properly while using mysql_fetch_array. 
Heres what I have and it returns an empty array. 
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established arrayd_join);
print ("</pre>")


Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ronesult2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")


Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ron

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query(&quote;SELECT dict.word1 FROM dict&quote;);
$result2 = mysql_query(&quote;SELECT dict2.word2 FROM dict2&quote;);
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print (&quote;&lt;pre&gt;&quote;);
print_r ($emulated_join);
print (&quote;&lt;/ps well. I think my main problem was I did not have indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array. 
Heres what I have and it returns an empty array. 
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ronproperly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine forroblem was I did not have indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ronin problem was I did not have indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query(&quote;SELECT dict.word1 FROM dict&quote;);
$result2 = mysql_query(&quote;SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulatedrks well. I think my main problem was I did not have indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array. 
Heres what I have and it returns an empty array. 
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ronthrough it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query(&quote;SELECT dict.word1 FROM dict&quote;);
$result2 = mysql_query(&quote;SELECT dict2.word2 FROM dict2&quote;);
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print (&quote;e query works well. I think my main problem was I did not have indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array. 
Heres what I have and it returns an empty array. 
Any Ideas.

Code: Select all

$result1 = mysql_query(&quote;SELECT dict.word1 FROM dict&quote;);
$result2 = mysql_query(&quote;SELECT dict2.word2 FROM dict2&quote;);
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print (&quote;&lt;pre&gt;&quote;);
print_r ($emulated_join);
print (&quote;&lt;/pre&gt;&quote;)
Using an allready established array emulatedjoin works lem was I did not have indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict&quote;);
$result2 = mysql_query(&quote;SELECT dict2.word2 FROM dict2&quote;);
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2xes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array. 
Heres what I have and it returns an empty array. 
Any Ideas.

Code: Select all

$result1 = mysql_query(&quote;SELECT dict.word1 FROM dict&quote;);
$result2 = mysql_query(&quote;SELECT dict2.word2 FROM dict2&quote;);
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print (&quote;&lt;pre&gt;&quote;);
print_r ($emulated_join);
print (&quote;&lt;/pre&gt;&quote;)
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ronly. The query works well. I think my main problem was I did not have indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ronave indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ronly. The query works well. I think my main problem was I did not have indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a dexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready es. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
RonI have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ronote;SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($rid not have indexes. I indexed the 2 colums to compare and it rolls right through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array.
Heres what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query(&quote;SELECT dict2.word2 FROM dict2&quote;);
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print (&quote;t through it now..

One question on array_intersect for future referecne. I still cant get it to work properly while using mysql_fetch_array. 
Heres what I have and it returns an empty array. 
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Rones what I have and it returns an empty array.
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($rnt get it to work properly while using mysql_fetch_array. 
Heres what I have and it returns an empty array. 
Any Ideas.

Code: Select all

$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")
Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ron
$result1 = mysql_query("SELECT dict.word1 FROM dict");
$result2 = mysql_query("SELECT dict2.word2 FROM dict2");
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$emulated_join = array_intersect($row1, $row2);
print ("<pre>");
print_r ($emulated_join);
print ("</pre>")


Using an allready established array emulatedjoin works fine for me, but when I try it with db data its a no go..
Any help appreciated..
Thanks.
Ron

Posted: Fri Jul 08, 2005 5:17 am
by timvw
http://www.php.net/mysql_fetch_array only returns 1 row per call...

Code: Select all

$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
  $dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
  $wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);
$dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
$wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);

);

p]
$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
$dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
$wordrows[] = $row;
}

$join = array_intersectp.net/mysql_fetch_array[/url] only returns 1 row per call...

Code: Select all

$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
  $dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
  $wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);
ql_fetch_array($rs1))
{
$dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
$wordrowsї] = $row;
}

$join = array_intersect($dictrows, $wordrows);

($row = mysql_fetch_array($rs2))
{
$wordrowsї] = $row;
}

$join = array_intersect($dictrows, $wordrows);

[/phw = mysql_fetch_array($rs1))
{
$dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
$wordrowsї] = $row;
}

$join = array_intersect($dictrows, $wordrows);

ysql_fetch_array($rs1))
{
$dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
$wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);

= array();
while ($row = mysql_fetch_array($rs1))
{
$dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
$wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);

row per call...

Code: Select all

$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
  $dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
  $wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);
[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
$wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);
}

$join = array_intersect($dictrows, $wordrows);

drows);

rns 1 row per call...

Code: Select all

$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
  $dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
  $wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);
$rs2))
{
$wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);

row = mysql_fetch_array($rs2))
{
$wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);


$dictrows[] = $row;
}


$wordrows = array();
while ($row =array[/url] only returns 1 row per call...

Code: Select all

$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
  $dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
  $wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);
array($rs2))
{
$wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);

1 row per call...

Code: Select all

$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
  $dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
  $wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);
rns 1 row per call...

Code: Select all

$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
  $dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
  $wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);
h_array[/url] only returns 1 row per call...

Code: Select all

$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
  $dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
  $wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);
_array($rs1))
{
$dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
$wordrowsї] = $row;
}

$join = array_intersect($mysql_fetch_array[/url] only returns 1 row per call...

Code: Select all

$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
  $dictrows&#1111;] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
  $wordow per call...

Code: Select all

$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
  $dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
  $wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);
b7925c0f]
$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
$dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
$wordrowsї] = $row;
}

$join = array_intersect($dictrows, $wordrows);

[/php:1:99bray();
while ($row = mysql_fetch_array($rs2))
{
$wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);

p.net/mysql_fetch_array[/url] only returns 1 row per call...

Code: Select all

$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
  $dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
  $wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);
php]
$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
$dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
$wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);

p.net/mysql_fetch_array[/url] only returns 1 row per call...

Code: Select all

$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
  $dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
  $wordrows[] = $row;
}

$join = array_intersect
$dictrows = array();
while ($row = mysql_fetch_array($rs1))
{
  $dictrows[] = $row;
}


$wordrows = array();
while ($row = mysql_fetch_array($rs2))
{
  $wordrows[] = $row;
}

$join = array_intersect($dictrows, $wordrows);