Wow, and I wonder at times why PHP is so popular... Not being a Guru at PHP what you are trying to convert here is very simple, and this is not tested but as close to being right as I can think.
<cfquery name="result" datasource="" username="#username#" passwqord="#password#"> SELECT nimid, level, message, source FROM nas_alarms LIMIT #url.start#, #url.limit# </cfquery> Now I have not included the required cfqueryparams, which you should look into as a security measure. Once you have this returned the variable result will hold the query. So when you want the number of records returned you can use result.recordCount as the number of records returned. When you talk about JSon, you dont mention which version of ColdFusion, so you can either use the library from CFlibs to create the JSOn or you can use ColdFusion to create the JSON. Eitherway the amount of code is much simpler than what you have there in the PHP. -- Regards, Andrew Scott WebSite: http://www.andyscott.id.au/ Google+: http://plus.google.com/108193156965451149543 On Wed, Jan 11, 2012 at 2:47 AM, Tom Small <[email protected]> wrote: > > Hi, I need to convert php to coldfusion. Would appreciate some help, > thanks.... > > <?php > #First we include our credentials file > # FileName="connect.php" > $hostname = "localhost"; > $database = "nimsoftslmdev"; > $username = "root"; > $password = "xxx"; > > #And now we connect to the database > //connection String > > //connection String > $con = mysql_connect($hostname, $username, $password) or die('Could not > connect: ' . mysql_error()); > //select database > mysql_select_db($database, $con); > //Select The database > $bool = mysql_select_db($database, $con); > if ($bool === False){ > print "can't find $database"; > } > > > $start = ($_REQUEST["start"] == null)? 0 : $_REQUEST["start"]; > $limit = ($_REQUEST["limit"] == null)? 200 : $_REQUEST["limit"]; > > // Gather all pending requests > $query = "SELECT > nimid, > level, > message, > source > FROM nas_alarms" ; > > $query .= " ORDER BY level ASC "; > $query .= " LIMIT ".$start.",".$limit; > > $result = mysql_query($query, $con); > > // Here we do the count > $query_c = "SELECT > nimid, > level, > message, > source > FROM nas_alarms" ; > > //get total > $count_result = mysql_query($query_c, $con); > $total = mysql_num_rows($count_result); > > if (mysql_num_rows($result) > 0){ > while($obj = mysql_fetch_object($result)) > { > $arr[] = $obj; > } > > // Now create the json array to be sent to our datastore > > $myData = array('myInventory' => $arr, 'totalCount' => $total); > echo json_encode($myData); > return; > exit(); > > } > > else { // If no requests found, we return nothing > > $myData = array('myInventory' => '', 'totalCount' => '0'); > echo json_encode($myData); > return; > exit(); > > } > > ?> > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349376 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

