EasyCFM.COM ColdFusion Forums / PHP to CFML / Simple PHP to CFM

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Simple PHP to CFM

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

GabrielHKY
03-13-2008 @ 11:30 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 1
Joined: Mar 2008

Hi guys... even simple but really blackened my day...
Please help me..

<?php
include 'config.php';
include 'opendb.php';

$query = "SELECT *, DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 AS age, year(birthday) as tahunlahir FROM tbl_helper WHERE  1=1";

if ($_POST['Education'] != ')
{
     $query = $query . " and education = '" . $_POST['Education'] . "'";
}

if ($_POST['Nationality'] != ')
{
     $query = $query . " and nationality = '" . $_POST['Nationality'] . "'";
}

if ($_POST['Sex'] != ')
{
     $query = $query . " and sex = '" . $_POST['Sex'] . "'";
}

if ($_POST['Location'] != ')
{
     $query = $query . " and location = '" . $_POST['Location'] . "'";    
}

if ($_POST['Age'] == 'More30')
{
     $query = $query . " and DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 > 30 ";    
}

if ($_POST['Age'] == 'Less30')
{
     $query = $query . " and DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 <= 30 ";    
}

if(isset($_POST['IsNewBorn']))
{
    $query = $query . " and newborn = 1 ";    

}

if(isset($_POST['IsElderly']))
{
    $query = $query . " and elderly = 1 ";    

}

if ($_POST['Cantonese'] != 'Fair')
{
     $query = $query . " and cantonese = '" . $_POST['Cantonese'] . "'";    
}

$query = $query . " ORDER BY id_helper";

//echo $query;

$result = mysql_query($query);
$RecordCount = mysql_num_rows($result);

$dob = date("Y", "timestamp");
$now = date("Y");

$age =  $now - $dob;

?>

<TR>
     <TD COLSPAN="3">
          <font color=003399 face="Arial" size="-1">
               <P><BR>We might have <B><?=$RecordCount;?></B> Record(s) to macth your criteria...</P>
          </FONT>
     </TD>
</TR>
<TR>
     <TD HEIGHT="50" COLSPAN="3"> </TD>
</TR>

<table width="391" border="0" cellspacing="5" cellpadding="3">
<FONT FACE="Arial">
<?
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{     
?>
<TR>
     <TD width="132" bgcolor=lightgrey>

  
         <img src="images/helper/<?echo $row['picture'];?>" WIDTH="93%" HSPACE="5" VSPACE="5" BORDER="0">
         
    </TD>
     <TD width="232" bgcolor=lightgrey valign="top"><font color=003399 face="Arial" size="-1">

<A HREF="details.php?search=<?=$row['id_helper'];?>"><strong><?echo $row['name'];?></strong></A><BR>
                  
                    <FONT FACE="WingDings" color=CC0000>(</FONT>
                
                <font color=003399 face="Arial" size="-1"><strong><?echo $row['phone'];?></strong><BR><BR></font>
                <font color=CC0000 face="Arial" size="-1"><B>Nationality: <?echo $row['nationality'];?><BR>
                Born on: <?echo $row['birthday'];?><BR>
                Experiences: <?echo $row['hk_exp'];?><BR>
                    Age: <?echo $row['age'];?><BR>
                    
                    <?
                    // hitung shio
                    $tahunlahir = $row['tahunlahir'];
                    $baseyear = 1948;
                    $elapseyear = $tahunlahir - $baseyear;
                    $cycles = floor($elapseyear / 12);
                    $incyear = $elapseyear - (12 * $cycles);
                    
                    $sql = "select shio from shio order by year limit $incyear,1";                                        
                    $res = mysql_query($sql);
                    $shio = "-";
                    while ($baris = mysql_fetch_array($res, MYSQL_NUM))                         
                    {                    
                         $shio = $baris[0];                    
                    }                    
                    ?>
                    Shio: <?echo $shio;?><BR>
                    </B></font>
                
               
              

    </TD>

</TR>

<?
}
mysql_free_result($result);
include 'closedb.php';
?>    


</FONT>
</TABLE>


Thanks very much...

dtempelmeyer
03-13-2008 @ 3:24 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 18
Joined: Oct 2006

When you initiate the $query variable, you would simply do:
<cfset query = "SELECT *, DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 AS age, year(birthday) as tahunlahir FROM tbl_helper WHERE  1=1" />


For the majority of the IF statements, you could use:
<cfif form.variable IS NOT "">...</cfif>


For the other few, you could:
<cfif IsDefined("form.variable")>...</cfif>


To concatenate the query variable, just do
<cfset query = query & "..." />


All of this is covered in the tutorials as well as the ColdFusion documentation.


Website Designed and Developed by Pablo Varando.