Jump to content

[SOLVED] sintax problems


bolter

Recommended Posts

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

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

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.

 

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.