Loading ...
Sorry, an error occurred while loading the content.
 

Re: [ydn-javascript] YUI Datatable using PHP

Expand Messages
  • Satyam
    This might help: http://satyam.com.ar/yui/#phpjson
    Message 1 of 2 , May 30, 2009
      This might help:

      http://satyam.com.ar/yui/#phpjson



      fsl_umer escribió:
      > I want to fetch data from database but this code only fetch one record so plz check this code and tell where I have to change the code reply soon
      >
      >
      >
      >
      > /* yadl_spaceid - Skip Stamping */
      >
      > // This script returns a JSON dataset of up to 1396 records in 14 columns
      > // "extid","name","date","price","number","address","company","desc","age","title","phone","email","zip","country"
      >
      > header('Content-type: application/json');
      >
      > mysql_connect("localhost","root","")
      >
      > or die("Error in connecting to DB".mysql_error());
      >
      > mysql_select_db("company");
      >
      >
      > // Define defaults
      > $results = -1; // default get all
      > $startIndex = 0; // default start at 0
      > $sort = 'ticketid'; // the data is already sorted
      > $dir = 'asc'; // default sort dir is asc
      > $sort_dir = SORT_ASC;
      >
      > // How many records to get?
      > if(strlen($_GET['results']) > 0) {
      > $results = $_GET['results'];
      > }
      >
      > // Start at which record?
      > if(strlen($_GET['startIndex']) > 0) {
      > $startIndex = $_GET['startIndex'];
      > }
      >
      > // Sorted?
      > if(strlen($_GET['sort']) > 0) {
      > $sort = $_GET['sort'];
      > }
      >
      > // Sort dir?
      > if((strlen($_GET['dir']) > 0)) {
      > if (($_GET['dir'] == 'desc')) {
      > $dir = 'desc';
      > $sort_dir = SORT_DESC;
      > } else {
      > $dir = 'asc';
      > $sort_dir = SORT_ASC;
      > }
      > }
      >
      > // Return the data
      > returnData($results, $startIndex, $sort, $dir, $sort_dir);
      >
      > function returnData($results, $startIndex, $sort, $dir, $sort_dir) {
      > // All records
      > $allRecords = initArray();
      >
      > // Need to sort records
      > if(!is_null($sort)) {
      >
      > // Obtain a list of columns
      > foreach ($allRecords as $key => $row) {
      > $sortByCol[$key] = $row[$sort];
      > }
      >
      > // Valid sort value
      > if(count($sortByCol) > 0) {
      > // Sort the original data
      > // Add $allRecords as the last parameter, to sort by the common key
      > array_multisort($sortByCol, $sort_dir, $allRecords);
      > }
      > }
      >
      > // Invalid start value
      > if(is_null($startIndex) || !is_numeric($startIndex) || ($startIndex < 0)) {
      > // Default is zero
      > $startIndex = 0;
      > }
      > // Valid start value
      > else {
      > // Convert to number
      > $startIndex += 0;
      > }
      >
      > // Invalid results value
      > if(is_null($results) || !is_numeric($results) ||
      > ($results < 1) || ($results >= count($allRecords))) {
      > // Default is all
      > $results = count($allRecords);
      > }
      > // Valid results value
      > else {
      > // Convert to number
      > $results += 0;
      > }
      >
      > // Iterate through records and return from start index
      > $lastIndex = $startIndex+$results;
      > if($lastIndex > count($allRecords)) {
      > $lastIndex = count($allRecords);
      > }
      > $data = array();
      > for($i=$startIndex; $i<($lastIndex); $i++) {
      > $data[] = $allRecords[$i];
      > }
      > // Create return value
      > $returnValue = array(
      > 'recordsReturned'=>count($data),
      > 'totalRecords'=>count($allRecords),
      > 'startIndex'=>$startIndex,
      > 'sort'=>$sort,
      > 'dir'=>$dir,
      > 'records'=>$data
      > );
      > if ($_GET['meta']) {
      > $returnValue['meta'] = array(
      > array('key' => "ticketid",'label' => "ID",'sortable' => true),
      > array('key' => "pessengername",'label' => "Pessenger Name",'sortable' => true),
      > array('key' => "seatno",'label' => "Name",'sortable' => true),
      > array('key' => "bookingdate",'label' => "Date",'sortable' => true),
      > array('key' => "depaturedate",'label' => "Price",'sortable' => true),
      > array('key' => "routefrom",'label' => "Number",'sortable' => true),
      > array('key' => "routeto",'label' => "Address",'sortable' => true),
      > array('key' => "depaturetime",'label' => "Company",'sortable' => true),
      > array('key' => "pessengerquantity",'label' => "Description",'sortable' => true),
      >
      > array('key' => "price",'label' => "Country",'sortable' => true)
      > );
      > }
      > // JSONify
      > //print json_encode($returnValue);
      >
      > // Use Services_JSON
      > require_once('JSON.php');
      > $json = new Services_JSON();
      > echo ($json->encode($returnValue)); // Instead of json_encode
      > }
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      > function initArray() {
      > $sql= "select * from booking";
      >
      > $res = mysql_query($sql);
      >
      > while($row = mysql_fetch_array($res)){
      >
      > return array(
      >
      > array('ticketid'=>$row['ticketid'],'pessengername'=>$row['pessengername'], 'seatno'=>$row['seatno'], 'bookingdate'=>$row['bookingdate'], 'depaturedate'=>$row['depaturedate'], 'routefrom'=>$row['routefrom'], 'routeto'=>$row['routeto'], 'depaturetime'=>$row['depaturetime'], 'pessengerquantity'=>$row['pessengerquantity'], 'price'=>$row['price'])
      >
      > );
      >
      >
      > }
      >
      > }
      > ?>
      >
      >
      >
      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      >
      >
      > ------------------------------------------------------------------------
      >
      >
      > No virus found in this incoming message.
      > Checked by AVG - www.avg.com
      > Version: 8.5.339 / Virus Database: 270.12.44/2140 - Release Date: 05/28/09 18:09:00
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.