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 Coder
    Join Date
    Jun 2008
    Posts
    41
    Thanks
    4
    Thanked 0 Times in 0 Posts

    PHP within Coldfusion

    I am curious about using <cfinclude> to include an external file that has a call to a database and the parsing of the results. I'm wanting to do the call and the parse in PHP, but the page that it will be included on is Coldfusion. Is that possible?

  • #2
    New Coder
    Join Date
    Jun 2008
    Posts
    41
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I'm actually wanting to execute this connection, SQL call, and results display:

    PHP Code:
    <?php

    // Create the connection file with connection information

    $host "hostname";
    $username "username";
    $password "password"

    // Connect to Database

    $connection = @mysql_connect($host,$username,$password);
    mysql_select_db(database_name,$connection);

    $result mysql_query("SELECT DATE_FORMAT(date,'%b %d, %Y') as article_day, `article_name`, `article_link`, `article_text` FROM `table_name` WHERE `date` <= CURDATE() ORDER BY event_date LIMIT 3");


     while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)) {
        echo 
    '<div class="cssarticle">
        <div class="headline">'
    $row["article_name"] .'</div>
        <div class="articledate">'
    $row["article_day"].'</div>
        <div class="articleintro">'
    $row["article_text"].'</div>
        <div class="articlelink"><a href="'
    $row["article_link"].'">Read More...</a></div>
        </div>'
    ;
    }

    mysql_free_result($result);


    ?>
    I'm extremely, extremely new to Coldfusion, so if someone could help show me how to do this, it'd be better than the initial request of PHP in CF.

    Thanks so much!!

  • #3
    Regular Coder croatiankid's Avatar
    Join Date
    Jan 2006
    Posts
    665
    Thanks
    1
    Thanked 12 Times in 12 Posts
    You have to setup the database connection through ColdFusion Administrator. Once you do that, using the DB is as simple as
    Code:
    <cfquery datasource="database_name" name="example">
    SELECT DATE_FORMAT(date,'&#37;b %d, %Y') as article_day, `article_name`, `article_link`, `article_text` FROM `table_name` WHERE `date` <= CURDATE() ORDER BY event_date LIMIT 3
    </cfquery>
    <cfoutput query="example">
    <div class="cssarticle"> 
        <div class="headline">#article_name#</div> 
        <div class="articledate">#article_day#</div> 
        <div class="articleintro">#article_text#</div> 
        <div class="articlelink"><a href="#article_link#">Read More...</a></div> 
        </div>
    </cfoutput>
    A lot cleaner than PHP, right?


  •  

    Posting Permissions

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