Correction php query

MOSTAGHASSI
MOSTAGHASSI used Ask the Experts™
on
Hello;

I have a query as bellow:

		 $query_suggested_artandculturecat_article = "select tbarticles.title,tbarticles.deletitem,tbarticles.articleid,tbcategories.parentid,tbcategories.catid,tbarticlecategories.catname,tbphotos.photofilename,tbarticlecategories.catid
	 
from  tbarticles 
INNER JOIN tbphotos on tbphotos.articleid = tbarticles.articleid 
INNER JOIN tbarticlecategories on tbarticlecategories.articleid =  tbarticles.articleid
INNER JOIN tbcategories ON tbcategories.catid = tbarticlecategories.catid 


where tbarticles.deletitem='1'  AND tbcategories.catid ='$urlcomecatid'
ORDER BY  RAND()
LIMIT 9

Open in new window


and i want correct as :
if($urlcomecatid=166 OR 62)
 $urlcomecatid=175;

Open in new window

please let me know how can correct the query?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
Add these instructions before the query.  As other values need to be changed, just follow a similar pattern.
if($urlcomecatid == 166) $urlcomecatid=175;
if($urlcomecatid ==  62) $urlcomecatid=175;

Open in new window

Author

Commented:
But i did it before and have problem,because after this query i have another query and with  these 'if condition' the  $urlcomecatid remain 175 while i want that only in this query(that i posted its codes) it be  175 for those conditions.
Most Valuable Expert 2011
Top Expert 2016
Commented:
Then you would need to assign a different variable for use in this query.  Maybe something like this:
// SET A DEFAULT VALUE FOR THE VARIABLE
$thing = $urlcomecatid;

// CHANGE THE VARIABLE IF NEEDED
if($urlcomecatid == 166) $thing=175;
if($urlcomecatid ==  62) $thing=175;

// USE THE VARIABLE IN THE QUERY STRING
$query_suggested_artandculturecat_article =
"SELECT tbarticles.title,tbarticles.deletitem,tbarticles.articleid,tbcategories.parentid,tbcategories.catid,tbarticlecategories.catname,tbphotos.photofilename,tbarticlecategories.catid
FROM  tbarticles 
INNER JOIN tbphotos on tbphotos.articleid = tbarticles.articleid 
INNER JOIN tbarticlecategories on tbarticlecategories.articleid =  tbarticles.articleid
INNER JOIN tbcategories ON tbcategories.catid = tbarticlecategories.catid 
WHERE tbarticles.deletitem='1'  AND tbcategories.catid ='$thing'
ORDER BY  RAND()
LIMIT 9 /* etc, etc

Open in new window

If you're new to PHP and want some good learning resources, this article can help you find them (and more importantly, help you avoid the many obsolete and terrible old PHP examples that litter the internet!)
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

Author

Commented:
Thanks,sometimes there are simple solution that we don't think.
Most Valuable Expert 2011
Top Expert 2016

Commented:
Thanks for the points, and thanks for using E-E! ~Ray

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial