RON_ron Posted November 25, 2010 Share Posted November 25, 2010 I can't get the COUNT of the matching results? Please help. $SomeVar = myname; $queryU = "SELECT * FROM adxone WHERE username = '".$SomeVar."'"; $resultU = mysql_query($queryU); while($scoreP = mysql_fetch_array($resultU)) { $scoreP['roundzAa']; $scoreP['roundzAb']; $scoreP['roundzAc']; $scoreP['roundzAd']; $scoreP['roundzAe']; $scoreP['roundzAf']; $scoreP['roundzAg']; $scoreP['roundzAh']; } $WinV = 'resultA'; $query = "SELECT * FROM acs WHERE resultx = '".$WinV."'"; $result = mysql_query($query); while($scoreUsr = mysql_fetch_array($result)) { $scoreUsr = $scoreM1['winxa']; $scoreUsr = $scoreM1['winxb']; $scoreUsr = $scoreM1['winxc']; $scoreUsr = $scoreM1['winxd']; $scoreUsr = $scoreM1['winxe']; $scoreUsr = $scoreM1['winxf']; $scoreUsr = $scoreM1['winxg']; $scoreUsr = $scoreM1['winxh']; } $count1 = count( array_intersect($resultU, $result) ); echo($count1); mysql_query("UPDATE comp SET id=$count1 WHERE username = '".$SomeVar."'"); ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2010 Share Posted November 25, 2010 If you had error reporting on, I suspect you'd see that $result and $resultU aren't arrays. They are query result resources. Quote Link to comment Share on other sites More sharing options...
RON_ron Posted November 25, 2010 Author Share Posted November 25, 2010 Sorry!!!!!!!! Here's the code. But this sends the count 0 all the time?? Also an error message Warning: array_intersect() [function.array-intersect]: Argument #1 is not an array in /home/...../TEST.php on line 36 $SomeVar = myname; $queryU = "SELECT * FROM adxone WHERE username = '".$SomeVar."'"; $resultU = mysql_query($queryU); while($scoreP = mysql_fetch_array($resultU)) { echo $scoreP['roundzAa']; echo $scoreP['roundzAb']; echo $scoreP['roundzAc']; echo $scoreP['roundzAd']; echo $scoreP['roundzAe']; echo $scoreP['roundzAf']; echo $scoreP['roundzAg']; echo $scoreP['roundzAh']; } $WinV = 'resultA'; $query = "SELECT * FROM acs WHERE resultx = '".$WinV."'"; $result = mysql_query($query); while($scoreM1 = mysql_fetch_array($result)) { echo $scoreM1['winxa']; echo $scoreM1['winxb']; echo $scoreM1['winxc']; echo $scoreM1['winxd']; echo $scoreM1['winxe']; echo $scoreM1['winxf']; echo $scoreM1['winxg']; echo $scoreM1['winxh']; } $count1 = count( array_intersect($resultU, $result) ); echo($count1); mysql_query("UPDATE comp SET id=$count1 WHERE username = '".$SomeVar."'"); ?> I'm expecting this would return the count like this; E.g. Assuming database A holds these records $scoreP['roundzAa']; holds "AUS" $scoreP['roundzAb']; holds "AUS" $scoreP['roundzAc]; holds "AUS" $scoreP['roundzAd']; holds "RUS" $scoreP['roundzAe']; holds "RUS" Assuming database B holds these records $scoreM1['winxa']; holds "US" $scoreM1['winxb']; holds "AUS" $scoreM1['winxc']; holds "UK" $scoreM1['winxd']; holds "RUS" $scoreM1['winxe']; holds "AUS" echo = 2//match the results by ORDER and echo the COUNT. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2010 Share Posted November 25, 2010 $result and $resultU aren't arrays. They are query result resources. You need to build an array for each set of results in the while loop from each query, then use array_intersect() on those. Quote Link to comment Share on other sites More sharing options...
RON_ron Posted November 25, 2010 Author Share Posted November 25, 2010 I hope this is the way to do this. But it's giving me an error. Parse error: syntax error, unexpected ',' in /home/....../TEST.php on line 108 $SomeVar = myname; $queryU = "SELECT * FROM adxone WHERE username = '".$SomeVar."'"; $resultU = mysql_query($queryU); $scoreU = mysql_fetch_assoc($resultU); $userRa1 = $scoreU['roundzAa']; $userRa2 = $scoreU['roundzAb']; $userRa3 = $scoreU['roundzAc']; $userRa4 = $scoreU['roundzAd']; $userRa5 = $scoreU['roundzAe']; $userRa6 = $scoreU['roundzAf']; $userRa7 = $scoreU['roundzAg']; $userRa8 = $scoreU['roundzAh']; $WinV = 'resultA'; $query = "SELECT * FROM acs WHERE resultx = '".$WinV."'"; $result = mysql_query($query); $scoreM = mysql_fetch_assoc($result); $winRa1 = $scoreM['markwinxa']; $winRa2 = $scoreM['markwinxb']; $winRa3 = $scoreM['markwinxc']; $winRa4 = $scoreM['markwinxd']; $winRa5 = $scoreM['markwinxe']; $winRa6 = $scoreM['markwinxf']; $winRa7 = $scoreM['markwinxg']; $winRa8 = $scoreM['markwinxh']; $ArrayUsr=array($userRa1, $userRa2, $userRa3, $userRa4, $userRa5, $userRa6, $userRa7, $userRa8), $ArrayMrk=array($winRa1, $winRa2, $winRa3, $winRa4, $winRa5, $winRa6, $winRa7, $winRa8, ), $count1 = count( array_intersect($ArrayUsr, $ArrayMrk) ); echo($count1); mysql_query("UPDATE comp SET id=$count1 WHERE username = '".$SomeVar."'"); ?> Quote Link to comment Share on other sites More sharing options...
RON_ron Posted November 25, 2010 Author Share Posted November 25, 2010 I've spot the coding error and fixed it. it works... but not the way I expected. I'm expecting this would return the count like this; E.g. Assuming database A holds these records $scoreP['roundzAa']; holds "AUS" $scoreP['roundzAb']; holds "AUS" $scoreP['roundzAc]; holds "AUS" $scoreP['roundzAd']; holds "RUS" $scoreP['roundzAe']; holds "RUS" Assuming database B holds these records $scoreM1['winxa']; holds "US" $scoreM1['winxb']; holds "AUS" $scoreM1['winxc']; holds "UK" $scoreM1['winxd']; holds "RUS" $scoreM1['winxe']; holds "AUS" echo = 2//match the results by ORDER and echo the COUNT. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 25, 2010 Share Posted November 25, 2010 If you're not using the variables $userRa(1- or $winRa(1- any other places, there are ways to simplify this code. Here's one: <?php $SomeVar = myname; $queryU = "SELECT * FROM adxone WHERE username = '$SomeVar'"; $resultU = mysql_query($queryU); $scoreU = mysql_fetch_assoc($resultU); $WinV = 'resultA'; $query = "SELECT * FROM acs WHERE resultx = '$WinV'"; $result = mysql_query($query); $scoreM = mysql_fetch_assoc($result); $ArrayUsr = array(); $ArrayMrk = array(); foreach(range(a,h) as $ltr) { $ArrayUsr[] = $scoreU['roundzA' . $ltr]; $ArrayMrk[] = $scoreM['markwin' . $ltr]; } $count1 = count( array_intersect($ArrayUsr, $ArrayMrk) ); echo $count1 ; mysql_query("UPDATE comp SET id=$count1 WHERE username = '$SomeVar'"); ?> Ken Quote Link to comment Share on other sites More sharing options...
RON_ron Posted November 25, 2010 Author Share Posted November 25, 2010 Hi Ken.. that's brilliant. But how can I get the COUNT if result1 of databaseA MATCH with result1 on databaseB and result2 of databaseA MATCH with result2 on databaseB, etc... databaseA - result1, result2, result3... databaseB - result1, result2, result3... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.