Jump to content

conditional select statement


steveginer

Recommended Posts

Hi,
Is there any way you can make your WHERE clause conditional upon which variables are passed from the referring form?  Can one embed php tags within a query, if not what is the general approach to a problem like this?

It works OK in coldfusion but can't seem to figure out how to recreate this in php. Thanks. Here's the coldfusion code.

<cfquery name="xxxx" datasource="xxxx" username="xxxx" password="xxxx">
SELECT DISTINCT style.style, style.desc, style.group
FROM style
WHERE 0=0
<cfif URL.style IS NOT "">
AND style.style = '#URL.style#'
</cfif>
<cfif URL.desc IS NOT "">
AND style.desc like '#URL.desc#'
</cfif>
<cfif URL.group IS NOT "">
AND style.group = '#URL.group#'
</cfif>
<cfif URL.OTS IS NOT "">
AND stktot-ordtot+wiptot>#URL.OTS#</cfif>
<cfif URL.IMMED IS NOT "">
AND stktot-ordtot>#URL.IMMED#</cfif>
<cfif URL.makebuy IS NOT "">
AND style.makebuy = '#URL.makebuy#'
</cfif>
</cfquery>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.