0 Replies Latest reply on Feb 9, 2010 3:56 AM by flashste

    database & blob image

    flashste

      1. I have managed a mysql database connection using a web service in PHP as follows:

       

      <?php

       


      include "config.php";
      /* require the user as the parameter */
      if(isset($_GET['table']) && intval($_GET['table'])) {

       

          /* soak in the passed variable or set our own */
          $number_of_posts = isset($_GET['num']) ? intval($_GET['num']) : 10; //10 is the default
          $format = strtolower($_GET['format']) == 'json' ? 'json' : 'xml'; //xml is the default
          $table = intval($_GET['table']); //no default

       

          /* connect to the db */
          $link = mysql_connect($dbhost,$dbuser,$dbpass) or die('Cannot connect to the DB');
          mysql_select_db($dbname,$link) or die('Cannot select the DB');

       

          /* grab the posts from the db */
          $query = "SELECT * FROM Tickets  ORDER BY Ticket_No DESC LIMIT $number_of_posts";
      // echo $query;
        $result = mysql_query($query,$link) or die('Errant query:  '.$query);

       

        /* create one master array of the records */
        $posts = array();
        if(mysql_num_rows($result)) {
          while($post = mysql_fetch_assoc($result)) {
            $posts[] = array('post'=>$post);
          }
        }

       

        /* output in necessary format */
        if($format == 'json') {
          header('Content-type: application/json');
          echo json_encode(array('posts'=>$posts));
        }
        else {
          header('Content-type: text/xml');
          echo '<posts>';
          foreach($posts as $index => $post) {
            if(is_array($post)) {
              foreach($post as $key => $value) {
                echo '<',$key,'>';
                if(is_array($value)) {
                  foreach($value as $tag => $val) {
                    echo '<',$tag,'>',htmlentities($val),'</',$tag,'>';
                  }
                }
                echo '</',$key,'>';
              }
            }
          }
          echo '</posts>';
        }

       

        /* disconnect from the db */
        @mysql_close($link);
      }

       

      I created a form based on this and can select a record.

       

      I now need to fill a grid with data from a table with a paging to scroll through the data. Is there a tutorial on this.

       

       

      2. Also how do I view images from a blob field in a mysql database. And can these images be inserted into a grid for viewing?