This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 5th, 2012  |  syntax: PHP  |  size: 1.09 KB  |  views: 39  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. ?>
clone this paste RAW Paste Data