bolter Posted June 27, 2009 Share Posted June 27, 2009 Hey Everyone, I'm pretty new at PHP and programming is not my main activity, I do it for fun and utility so I'm not very expert with it. Anyway I have two tables (mysql) like the one I listed below, and I want to see if for each same ID the color is equal and if that is true, increment a counter. tab 1 id color NO001 B NO002 Y NO003 G tab2 NO001 B NO002 Y NO003 G this is what I wrote so far $qry1 = mysql_query("SELECT * FROM tab1 ORDER BY id ASC"); while($row = mysql_fetch_array($qry1)) { $qry2 = mysql_query("SELECT color FROM tab2 WHERE id=".$row['id']); $result2 = mysql_fetch_assoc($qry2); if($row($row['color'] == $result2)) { if($result2 == "B") {$b++;} elseif($result2 == "R") {$r++;} elseif($result2 == "Y") {$y++;} elseif($result2 == "G") {$g++;} } } only it doesn't work mainly for a bunch of sintax errors. any help would be appreciated. thanks Bolter Link to comment https://forums.phpfreaks.com/topic/163900-solved-sintax-problems/ Share on other sites More sharing options...
JJ2K Posted June 27, 2009 Share Posted June 27, 2009 $qry2 = mysql_query("SELECT color FROM tab2 WHERE id=".$row['id']); should be $qry2 = mysql_query("SELECT color FROM tab2 WHERE id = '$row['id']' "); Link to comment https://forums.phpfreaks.com/topic/163900-solved-sintax-problems/#findComment-864730 Share on other sites More sharing options...
bolter Posted June 27, 2009 Author Share Posted June 27, 2009 thanks. I corrected that, but then I think that $row[id] should be without the ' $qry2 = mysql_query("SELECT color FROM tab2 WHERE id = '$row[id]' "); am I correct? $qry2 = mysql_query("SELECT color FROM tab2 WHERE id=".$row['id']); should be $qry2 = mysql_query("SELECT color FROM tab2 WHERE id = '$row['id']' "); Link to comment https://forums.phpfreaks.com/topic/163900-solved-sintax-problems/#findComment-864733 Share on other sites More sharing options...
bolter Posted June 27, 2009 Author Share Posted June 27, 2009 Fatal error: Function name must be a string if($row($row['color'] == $result2)) Link to comment https://forums.phpfreaks.com/topic/163900-solved-sintax-problems/#findComment-864735 Share on other sites More sharing options...
JJ2K Posted June 27, 2009 Share Posted June 27, 2009 What exactly do you want to return from your function, you said: "and I want to see if for each same ID the color is equal and if that is true, increment a counter" could you explain this a bit better please so i understand what your trying to do, i understand your tables though just not what you want to do with them. Link to comment https://forums.phpfreaks.com/topic/163900-solved-sintax-problems/#findComment-864756 Share on other sites More sharing options...
bolter Posted June 27, 2009 Author Share Posted June 27, 2009 what I want to do is, for each ID, see if the color is the same, and if it is increment the counter let's say color of id NO001 in tab 1 and tab2 is B i want counter to intrement. Link to comment https://forums.phpfreaks.com/topic/163900-solved-sintax-problems/#findComment-864775 Share on other sites More sharing options...
JJ2K Posted June 27, 2009 Share Posted June 27, 2009 Shouldn't the line: if($row($row['color'] == $result2)) Be if ($result2['color'] == $row['color']) Link to comment https://forums.phpfreaks.com/topic/163900-solved-sintax-problems/#findComment-864800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.