Advertisement
Guest User

Untitled

a guest
Jul 5th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  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. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement