Creating a table with mysql, php and ajax (with jquery)

前端 未结 3 1453
一整个雨季
一整个雨季 2021-01-06 04:41

For my new project i want the so modern approach of not needing to reload a page on every database request. :) I want the script to query the database and create a table wit

3条回答
  •  滥情空心
    2021-01-06 05:00

    You may invert the logic, and do it on client side, using a library that does that automatically, like http://phery-php-ajax.net Instead of creating the table on the server side, send it as JSON to the browser, which is faster, and build your table:

    Phery::instance()->set(array(
    'load' => function(){
      /* rest of mysql code */
      $rows = array();
      while($row = mysql_fetch_assoc($facebook)) { $rows[] = $row; }
      return PheryResponse::factory()->json($rows);
    })->process();
    

    then in the client side inside $(function(){});

    $(function(){
      var $result_table = $('#result_table'); 
      $result_table.phery('make', 'load');
      $result_table.bind('phery:json', function(e, data){
        var $this = $(this);
        for (var i = 0; i < data.length; i++) {
          $this.append($('', {
            'html': '' + data[i].row_name + ''
          }));
        }
      });
      $result_table.phery('remote');
    });
    

提交回复
热议问题