Jump to content

Loop data of each row?


Miss-Ruth

Recommended Posts

Thanks Pikachu2000 and Maq.

 

I'm trying to match data from table1 against table2, and then update the 'MatchType' column with the matching count. I know how to match table1 against table2 and get the matching count. But I dont know how to do it to all rows on the fly when the table2 is updated. Could you show me a sample how to update row by rwo on the fly?

 

$query =  "SELECT * FROM table1 WHERE shop = 'B-11'";
//instead of B-11 how can I call each row once to update the "MatchType" column?

 

table1

shop          JAN                  FEB                  MARCH        MatchType

B-11            paid -R            paid -R            paid -F         

B-12            paid -F            paid -F            paid -F         

B-13            paid -R            paid -R            paid -R         

 

 

table2

SHOP          JAN                  FEB                  MARCH

2010            paid -F            paid -R            paid -F         

 

Alright. Let me ask you the question this way... How can I update all the rows in MatchType of table1 using the following code?

 

table1

shop          JAN                  FEB                  MARCH        MatchType

B-11            paid -R            paid -R            paid -F         

B-12            paid -F            paid -F            paid -F         

B-13            paid -R            paid -R            paid -R         

 

 

table2

SHOP          JAN                  FEB                  MARCH

2010            paid -F            paid -R            paid -F 

 

 

$MyArray1 = array();
$MyArray2 = array();
db1
$Variable1 = mysql_real_escape_string($_POST['roundonex'], $conn);
$Variable1 = $_POST['name'];
$queryA1 =  "SELECT * FROM table1 WHERE username = '".$Variable1."'";
$resultA = mysql_query($queryA1);
$scoreA = mysql_fetch_assoc($resultA);
foreach (range('a','h') as $ltr) {
$MyArray1[] = array($scoreA['roundzA' . $ltr]);
}
db2
$$Variable2 = 'roundA';
$query1 =  "SELECT * FROM table2 WHERE roundx = '".$$Variable2."'";
$result = mysql_query($query1);
scoreB = mysql_fetch_assoc($result);
foreach (range('a','h') as $ltr) {
$MyArray2[] = array(scoreB['markwinx' . $ltr]);
}
$count = array();
for($i=0;$i<count($MyArray1);++$i) {
$count[$i] = count(array_intersect($MyArray1[$i],$MyArray2[$i]));
}
$count1 = array_sum($count);[/sup]

Archived

This topic is now archived and is closed to further replies.

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