Jump to content


Photo

MySql count query from different tables


  • Please log in to reply
1 reply to this topic

#1 astaroth

astaroth
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 30 April 2003 - 12:53 PM

I have problem.... i need a count of how many firms name are searched in the table of Requests, The firm ID is in the table Com...



$name=("SELECT SUBSTRING(Name,1,4) FROM Com WHERE Com.ComID=\'$CID\'"); 

$query=("SELECT count(*) as CD FROM Com LEFT JOIN Requests ON 

Com.ComID=Requests.ID WHERE  Action=\'search\' && Keyword like 

\'%$name%\'");



    $result=mysql_query("$query");

    while($r = mysql_fetch_array($result)) {

         $r[CD];

}





The problem is that SQL dont accepts $name in Keyword like \'%$name%\'\");
May be someone can help.....any ideas?? :?:
Astaroth [br]----------- [br]i am so stupid to read the manual

#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 30 April 2003 - 02:35 PM

How about using

mysql_num_rows

$query=("SELECT count(*) as CD FROM Com LEFT JOIN Requests ON 

Com.ComID=Requests.ID WHERE  Action=\'search\' && Keyword like 

\'%$name%\'"); 

$result = mysql_query($query,$db);

$numrows = mysql_num_rows($result);

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users