Jump to content

Coding help to match and count array results


RON_ron

Recommended Posts

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."'");
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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."'");
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

If you're not using the variables $userRa(1-8) or $winRa(1-8) 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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.