Miss-Ruth Posted December 7, 2010 Share Posted December 7, 2010 How can all records in a mysql be called row by row using a loop? Quote Link to comment https://forums.phpfreaks.com/topic/220931-loop-data-of-each-row/ Share on other sites More sharing options...
Pikachu2000 Posted December 7, 2010 Share Posted December 7, 2010 Where are you stuck? Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/220931-loop-data-of-each-row/#findComment-1144070 Share on other sites More sharing options...
Maq Posted December 7, 2010 Share Posted December 7, 2010 Look at some of these examples - http://php.net/manual/en/function.mysql-fetch-array.php Quote Link to comment https://forums.phpfreaks.com/topic/220931-loop-data-of-each-row/#findComment-1144111 Share on other sites More sharing options...
Peter-Colman Posted December 8, 2010 Share Posted December 8, 2010 oops! Quote Link to comment https://forums.phpfreaks.com/topic/220931-loop-data-of-each-row/#findComment-1144283 Share on other sites More sharing options...
Miss-Ruth Posted December 8, 2010 Author Share Posted December 8, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/220931-loop-data-of-each-row/#findComment-1144286 Share on other sites More sharing options...
Maq Posted December 8, 2010 Share Posted December 8, 2010 Not sure exactly what you're trying to do so you may need to elaborate. But if I guess correctly you would want to read about mysql trigger - http://dev.mysql.com/doc/refman/5.0/en/triggers.html Quote Link to comment https://forums.phpfreaks.com/topic/220931-loop-data-of-each-row/#findComment-1144515 Share on other sites More sharing options...
Miss-Ruth Posted December 8, 2010 Author Share Posted December 8, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/220931-loop-data-of-each-row/#findComment-1144554 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.