Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Translating a ColdFusion page into PHP - newbie questions

    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!

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    1. I have no idea what the CFPARAM tag is actually doing, but I have the feeling that it could be related to HTTP/Server parameters sent to the script? If so, check the PHP manual for $_GET, $_POST, and $_SERVER.

    2. You can declare an empty string that receives its content on a certain condition, and later use that variable in your SQL query. Example:

    PHP Code:
    $where "";

    if (
    $num 20) { // arbitrary condition
    $where " AND num < 20"
    }

    // ...

    $sql "
    SELECT
      name,
      age
    FROM
      test
    WHERE
      id < 1000
      $where 
    "

    Depending on the evaluation of the if-statement, $where contains either nothing and has no effect on the SQL query, or its contents refine the WHERE statement. The string contents of $where are actually inserted into the $sql string, so this portion looks like

    Code:
    WHERE
      id < 1000
      AND num < 20
    if the condition is true, that is.
    De gustibus non est disputandum.

  • #3
    New to the CF scene
    Join Date
    Nov 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ahhh, that's a great idea...thanks.

    the CFPARAM tag is a tag that sets a default value for a variable if that variable is not passed to the page through a POST or GET method.

    ex:

    <CFPARAM name="SomeVariable" default="value">

    sets the variable #SomeVariable# to the value "value". but if the page was called from a link (say mypage.cfm?SomeVariable="yomommasofat") then #SomeVariable# would have the value "yomommasofat" and the CFPARAM tag will be ignored.

    the same can also be accomplished in CF as follows

    <CFIF NOT IsDefined(SomeVariable)>
    <CFSET SomeVariable="value">
    </CFIF>

    Where the IsDefined() function returns TRUE is the variable it is passed has a value, and FALSE otherwise.

    Is there a function in PHP that is equivalent to the IsDefined() CF function? I looked in the function reference at php.net but I couldn't find anything.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •