• Hi all
    I am not very technical in terms of website building and feel i have done an ok job on my website.

    i have a page for Our Properties, where all the properties I rent out appear with the use of a database an SQL query that brings them back.

    However, I have started to play with adding sliders for the picture of the property which i have found has slowed down the performance.

    I was thinking about adding pagination and after searching through the support on here and google i am at a lose as to what to do next.

    simply this is the page Our Properties i want to paginate in which 20 properties are to appear and then a user can click next page and the next 20 appear

    I am at a complete loss as to what to do.

    this is a snippet of my code if this helps

    [insert_php]$servername = "..........";$username = ".......";$password = "........";$dbname = ".........";
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    }
    $sql = "SELECT <code>Property Thumbnail URL</code>,<code>Property Title4HTML</code>,<code>Image Tag</code> FROM <code>Properties</code>,<code>Available</code> WHERE <code>Property Available Flag</code> = <code>Flag</code> ORDER BY <code>Property Number</code>";
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    echo
    "<tr>
    <td>" . $row['Property Thumbnail URL'] .
    "</td><td>" . $row['Property Title4HTML'] .
    "</td><td>" . $row['Image Tag'] .
    "</td>
    </tr>";
    }
    } else {
    echo "0 results";
    }
    $conn->close();
    [/insert_php]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter cragga_lfc

    (@cragga_lfc)

    Hi i have followed a few help topics on here and generated the following code

    but get this error:

    Parse error: syntax error, unexpected end of file in /homepages/46/d567671028/htdocs/clickandbuilds/WordPress/LuxorEstates/wp-content/plugins/insert-php/insert_php.php(48) : eval()’d code on line 81

    here is my code – any help appreciated

    [insert_php]$servername = ".........";$username = "........";$password = "........";$dbname = "..........";
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    }
    $sql = "SELECT <code>Property Thumbnail URL</code>,<code>Property Title4HTML</code>,<code>Image Tag</code> FROM <code>Properties</code>,<code>Available</code> WHERE <code>Property Available Flag</code> = <code>Flag</code> ORDER BY <code>Property Number</code>";
    if ($myrows) {
    foreach ( $myrows as $property ) {
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    echo
    "<tr>
    <td>" . $row['Property Thumbnail URL'] .
    "</td><td>" . $row['Property Title4HTML'] .
    "</td><td>" . $row['Image Tag'] .
    "</td>
    </tr>";
    }
    } else {
    echo "0 results";
    }
    $conn->close();
    
    //this is the counting number of page
    
    global $sql;
    
    $big = 999999999; // need an unlikely integer
    
    echo paginate_links( array(
    	'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    	'format' => '?paged=%#%',
    	'current' => max( 1, get_query_var('paged') ),
    	'total' => $sql->max_num_pages
    ) );
    
    // Test the use of paginate_links
    
    $rows_per_page = 7;
    $current = (intval(get_query_var('paged'))) ? intval(get_query_var('paged')) : 1;
    
    // $rows is the array that we are going to paginate.
    $rows = $wpdb->get_results("SELECT <code>Property Thumbnail URL</code>,<code>Property Title4HTML</code>,<code>Image Tag</code> FROM <code>Properties</code>,<code>Available</code> WHERE <code>Property Available Flag</code> = <code>Flag</code> ORDER BY <code>Property Number</code>");
    
    global $wp_rewrite;
    
    $pagination_args = array(
     'base' => @add_query_arg('paged','%#%'),
     'format' => '',
     'total' => ceil(sizeof($rows)/$rows_per_page),
     'current' => $current,
     'show_all' => false,
     'type' => 'plain',
    );
    
    if( $wp_rewrite->using_permalinks() )
     $pagination_args['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . 'page/%#%/', 'paged');
    
    if( !empty($wp_query->query_vars['s']) )
     $pagination_args['add_args'] = array('s'=>get_query_var('s'));
    
    echo paginate_links($pagination_args);
    
    $start = ($current - 1) * $rows_per_page;
    $end = $start + $rows_per_page;
    $end = (sizeof($rows) < $end) ? sizeof($rows) : $end;
    
    echo '<br />';
    for ($i=$start;$i < $end ;++$i ) {
     $property = $rows[$i];
     echo "I:$i  ID:{$row->ID}  Title:{$row->post_title} <br />";
    
    }
    
    [/insert_php]
    Thread Starter cragga_lfc

    (@cragga_lfc)

    hi for anyone who can help i have built a little more and getting somewhere on page

    you will see i can get a list but:

    – pagenitation not quite working
    – and i can’t retrieve the data from the sql database

    any help would be great

    [insert_php]$servername = "db567706584.db.1and1.com";$username = "dbo567706584";$password = "Nico_1983!";$dbname = "db567706584";
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    }
    global $wpdb;
    $myrows = $wpdb->get_results( "SELECT * FROM <code>Properties</code>,<code>Available</code> WHERE <code>Property Available Flag</code> = <code>Flag</code> ORDER BY <code>Property Number</code>", OBJECT);
    if ($myrows) {
    foreach ( $myrows as $property ) {
    echo "<table width='100%' align='center' border='3px solid grey'>";
    
    echo"<tr>";
    echo"<th>Picture</th>";
    echo "<th>Details</th>";
    echo "<th>More Info</th>";
    echo "</tr>";
    
    echo "<tbody>";
    echo "<tr>";
    echo "<td>Property Thumbnail URL</td>";
    echo "<td>Property Title4HTML</td>";
    echo "<td>Image Tag</td>";
    echo "</tr>";
    echo "</tbody>";
    }
    echo "</table>";
    }
    global $wp_query;
    
    $big = 999999999; // need an unlikely integer
    
    echo paginate_links( array(
    	'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    	'format' => '?paged=%#%',
    	'current' => max( 1, get_query_var('paged') ),
    	'total' => $wp_query->max_num_pages
    ) );
    
    // Test the use of paginate_links
    
    $rows_per_page = 7;
    $current = (intval(get_query_var('paged'))) ? intval(get_query_var('paged')) : 1;
    
    // $rows is the array that we are going to paginate.
    $rows = $wpdb->get_results("SELECT * FROM <code>Properties</code>,<code>Available</code> WHERE <code>Property Available Flag</code> = <code>Flag</code> ORDER BY <code>Property Number</code>");
    
    global $wp_rewrite;
    
    $pagination_args = array(
     'base' => @add_query_arg('paged','%#%'),
     'format' => '',
     'total' => ceil(sizeof($rows)/$rows_per_page),
     'current' => $current,
     'show_all' => false,
     'type' => 'plain',
    );
    
    if( $wp_rewrite->using_permalinks() )
     $pagination_args['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . 'page/%#%/', 'paged');
    
    if( !empty($wp_query->query_vars['s']) )
     $pagination_args['add_args'] = array('s'=>get_query_var('s'));
    
    echo paginate_links($pagination_args);
    
    $start = ($current - 1) * $rows_per_page;
    $end = $start + $rows_per_page;
    $end = (sizeof($rows) < $end) ? sizeof($rows) : $end;
    
    echo '<br />';
    for ($i=$start;$i < $end ;++$i ) {
     $property = $rows[$i];
     echo "I:$i  ID:{$row->ID}  Title:{$row->post_title} <br />";
    
    }
    
    [/insert_php]
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Paginate Results from SQL Query’ is closed to new replies.