code_junkie

showing related data from mysql in ajax

Nov 12th, 2011
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. echo '<div id="Result">Content goes here</div>';
  2. echo "<h1>Table: {$table}</h1>";
  3. echo "<table border='1'><tr>";
  4. // printing table headers
  5. for($i=0; $i<$fields_num; $i++)
  6. {
  7. $field = mysql_fetch_field($result);
  8. echo "<td>{$field->name}</td>";
  9. }
  10. echo "</tr>n";
  11. // printing table rows
  12. while($row = mysql_fetch_row($result))
  13. {
  14. echo "<tr>";
  15.  
  16. // $row is array... foreach( .. ) puts every element
  17. // of $row to $cell variable
  18. foreach($row as $cell)
  19. echo '<td><a href="#" onclick="GetAuctionData()">' . $cell . '</a></td>';
  20.  
  21. echo "</tr>n";
  22. }
  23.  
  24. echo "<table border='1' width='100%'>
  25. <tr>
  26. <th>test1</th>
  27. <th>test2</th>
  28. <th>test3</th>
  29. </tr>";
  30.  
  31. $sql="select * from auctions where ARTICLE_NO='110294394238';
  32. $result = mysql_query($sql);
  33. while ($row = mysql_fetch_array($result))
  34. {
  35. echo "<tr>
  36. <td>".$row['SELLER_ID']."</td>
  37. <td>".$row['ACCESSSTARTS']."</td>
  38. <td>".$row['ARTICLE_NAME']."</td>
  39. </tr>";
  40. }
  41. echo "</table>";
  42.  
  43. function GetAuctionData()
  44. {
  45. xmlHttp=GetXmlHttpObject()
  46. if(xmlHttp==null)
  47. {
  48. alert("Your browser is not supported?")
  49. }
  50. var url="get_auction.php?"
  51. url=url+"cmd=GetAuctionData"
  52. url=url+"&sid="+Math.random()
  53. xmlHttp.onreadystatechange = FetchComplete;
  54. xmlHttp.open("GET",url,true)
  55. xmlHttp.send(null)
  56. }
  57.  
  58. echo '<td><a href="#" onclick="GetAuctionData('. $article_no . ')">' . $cell . '</a></td>';
  59.  
  60. function GetAuctionData(article_no) {
  61. new Ajax.Updater('div_to_update', 'get_auction.php', {
  62. method: 'get',
  63. parameters: {cmd: 'GetAuctionData', sid: Math.random(), article: article_no}
  64. }
  65. }
Add Comment
Please, Sign In to add comment