SHARE
TWEET

Untitled

a guest Jul 5th, 2012 43 Never
  1. <?php
  2.         // Open the connection
  3.                 $con = mysql_connect("localhost","user","password")
  4.                 or die('No connection could be established: ' . mysql_error());
  5.        // Select the database
  6.                 mysql_select_db("db", $con);
  7.                
  8.         //in our html file, there is an id submitted which we are using here
  9.                 $result = mysql_query("SELECT * from tablename where id = '".$_POST['chooseId']."'")
  10.                 or die ("MySQL-Error: " . mysql_error());  
  11.  
  12.         // Here we fill our data into an array
  13.                 while($row = mysql_fetch_array($result))
  14.                 {
  15.        
  16.         // "First"=>$row['First'] means you will be able to show the first row of your record by referencing
  17.                 data.First later in your jQuery script
  18.                     $data = array ("First"=>$row['First'],"Second"=>$row['Second']);
  19.                    
  20.         // We encode our array as JSON, as it is easier to process
  21.                     $jsondata = json_encode($data);
  22.                    
  23.                 }
  24.  
  25.         // Finally we return the data
  26.                 echo "$jsondata";
  27. ?>
RAW Paste Data
Top