Click to See Complete Forum and Search --> : Translating a ColdFusion page into PHP - newbie questions


Rubix
12-16-2003, 04:57 PM
So I'm trying to translate a simple application I wrote in ColdFusion into PHP. Does anyone know what the PHP equivalent of a <CFPARAM> tag would be?

Also, I'm trying to translate the following conditional query, and am unsure of the best way to do it:

<CFQUERY DATASOURCE="MarketNotes" NAME="GetNotes">
SELECT NoteID, Date, Headline, SubjectName, SourceName
FROM notes, subjectareas, sources
WHERE subjectareas.SubjectAreaID = notes.SubjectAreaID AND notes.SourceID = sources.SourceID
<!--- if a particular subject was selected --->
<cfif NOT SubjectView IS "all">
AND #SubjectView# = notes.SubjectAreaID
</cfif>
ORDER BY #sort# #sortdir#
</CFQUERY>

I can't figure out how to throw a conditional statement into the middle of a php-based sql query. I start out with

$GetNotes ="SELECT (yada yada yada) ... "

but can't figure out how you throw a conditional statement into the middle of that.

Any suggestions would be greatly appreciated, thanks!

PunkSktBrdr01
12-16-2003, 09:29 PM
Well, I don't know much about CF, so I can't really tell which things are variables, but I think this might be what you want:


// $query will contain the SQL query

$query = "SELECT stuff, moreStuff, evenMoreStuff FROM place, anotherPlace, yetAnotherPlace WHERE something = " . $theThing . " AND somethingElse = " . $theOtherThing;

// if $thisVariable is not equal to "this string", '"ORDER BY " . $theOrder' will be added to the end of $query

if ($thisVariable != "this string") {
$query .= "ORDER BY " . $theOrder;
}

YoN
12-17-2003, 11:49 AM
Originally posted by PunkSktBrdr01

// if $thisVariable is not equal to "this string", '"ORDER BY " . $theOrder' will be added to the end of $query
if ($thisVariable != "this string") {
$query .= "ORDER BY " . $theOrder;
}

Don't forget the space before ORDER BY for the query to work: if ($thisVariable != "this string") {
$query .= " ORDER BY " . $theOrder;
}

PunkSktBrdr01
12-17-2003, 04:31 PM
Oops! :)