How to Create Pages From a Database in Drupal

104 5
    • 1). Go to sites/includes and locate "pager.inc. " Double click the file to open it. Pager.inc includes Drupal API functions, which helps illustrate database results as a set of pages. You can view the definition of pager_query function in this file.

    • 2). Go to your PHPMyAdmin. Click "Query" to start a SQL query. Create a data table items in MySQL using code:

      CREATE TABLE 'items' (

      'title' varchar(255) NOT NULL default '',

      'description' varchar(255) NOT NULL )

      Insert data into the new tables via code:

      INSERT INTO items (title, description) VALUES('item1', 'The first item' )

    • 3). Go to sites/all/ and find the php file you want to insert the query. Insert the following query into the php file:

      <?php

      $query = "SELECT title, description FROM {items}";

      $result = pager_query($query, 10, 0, NULL, $cat_id);

      ?>

      The first argument in pager_query is the query name to be executed. The second defines the number of query results to display on each page. The third argument shows the number of the page we are currently working with. The fourth represents $count_query while the last one specifies the parameter which needs to be passed to the query.

Source...

Leave A Reply

Your email address will not be published.