php - Mysql to JSON specific rows -


there mysql database, "events" table. in table have on 250 rows, different events, name, id, location, , start time. know how data table, want learn how specific rows.

how can rows start_time today?

my code:

//create database connection $db = mysql_connect("####","####","####"); if (!$db) {     die('could not connect db: ' . mysql_error()); }  //select database  mysql_select_db("rlidi37_timisoara",$db);  $result = mysql_query("select * events", $db);   //create array $json_response = array(); while ($row = mysql_fetch_array($result, mysql_assoc)) {      $row_array['name'] = $row['name'];     $row_array['location'] = $row['location'];     $row_array['id'] = $row['id'];     $row_array['start_time'] = $row['start_time'];      //push values in arr     array_push($json_response,$row_array);  }  echo json_encode($json_response); //close database connection fclose($db); 

first modify query add clause filter down results. once have results, can turn json 1 of 2 ways.

  1. if using plain php mysql functions, think have iterate on data create array of arrays each records associative array. can call json_encode on 2d array.

  2. if using pdo, check out pdo::fetch_obj option. see stack overflow question: pdostatement json


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -