What im missing, LIMIT & Next page are not working. it showing nothing.

<?php
include ('ini.php');
    $query = $_GET['query']; 
    $min_length = 3;
    $max_length = 15;
  if(strlen($query) >= $min_length)
  { 
        $query = htmlspecialchars($query); 
        $query = mysql_real_escape_string($query);  
  echo "<table border='0' width='' align='left' cellpadding='1' cellspacing='1'>";
  echo "<tr><h3>You have searched for $query... Please find the details of $query...</h3></tr>";
  echo "<tr align='center' bgcolor='#03acfa' > <td height='35px' width='125px'><b>Business Name</b></td> <td><b>Business Type</b></td> <td><b>Services Offering</b></td> <td><b>City</b></td></tr>";     
        $rowsPerPage = 10; //number of results you want to display 

$num = 1; //set the offset to start w/the num. of results (good for paging) 

$offset = ($num - 1) * $rowsPerPage; // to offset the limit count 
        $result = mysql_query("SELECT * FROM members WHERE (`NAME` LIKE '%".$query."%') OR (`SERVICES` LIKE '%".$query."%')") or die(mysql_error()); LIMIT, $rowsPerPage, $offset";
        if(mysql_num_rows($result) > 0)
  {
            while($results = mysql_fetch_array($result))
   { 
                echo "<tr align='center' bgcolor='#93dafb'><td height='25px'><a href='testpage.php?ID=".$results['ID']."'>".$results['Name']."</td> <td>".$results['Date']."</td> <td>".$results['Mode']."</td> <td>".$results['CITY']."</td></tr>";
            }

        }
        else{ 
            echo "<tr align='center' bgcolor='#fdee03'><td colspan='2' height='25px'>Sorry..not found in system you may Add it now Click Here</td><tr>"; 
   echo "</table>";  
        }   
    }
    else{ 
        echo "<tr align='center' bgcolor='#fdee03' font size='10'><td colspan='2' height='25px'>Your search keyword contains letters only ".$min_length;
    }
?>

Recommended Answers

All 9 Replies

error at Line# 18

It should show a parsing fatal error , always use:

error_reporting(E_ALL);
ini_set("display_errors", "1");

at least at development stage

Line 18 you have the LIMIT AFTER you closed the double quotes of the sql statement's string.
e.g.

<?php
$database = "test";
$username = "testuser";
$password = "testpassword";


$db = new PDO("mysql:host=localhost;dbname=".$database, $username, $password);
$selectByKeywordSql = "SELECT * FROM members WHERE NAME LIKE ? OR SERVICES LIKE ?";
$keyword = "%" . $query . "%";
$statement = $db->prepare( $selectByKeywordSql );
$statement->execute( array( $keyword , $keyword ) );
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
var_export($results); // Or what ever you want to do with the resulted array that is a 
// two dimentional array with first key the index of the resulted row and second key 
// the name of the table field 
?>

Don't use mysql_* functions they are deprecated (for many reasons) and will be removed.
@see https://www.daniweb.com/programming/web-development/tutorials/499320/common-issues-with-mysql-and-php

now it showing "
Parse error: syntax error, unexpected 'else' (T_ELSE) in /home/swatcorp/public_html/search/Result.php on line 20

<?php
$database = "host";
$username = "us";
$password = "us";
$db = new PDO("mysql:host=localhost;dbname=".$database, $username, $password);
$selectByKeywordSql = "SELECT * FROM Member WHERE NAME LIKE ? OR SERVICES LIKE ?";
$keyword = "%" . $query . "%";
$statement = $db->prepare( $selectByKeywordSql );
$statement->execute( array( $keyword , $keyword ) );
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
var_export($results); // Or what ever you want to do with the resulted array that is a 
// two dimentional array with first key the index of the resulted row and second key 
// the name of the table field 
  {
            while($results = mysql_fetch_array($result))
   { 
                echo "<tr align='center' bgcolor='#93dafb'><td height='25px'><a href='testpage.php?ID=".$results['ID']."'>".$results['Name']."</td> <td>".$results['Date']."</td> <td>".$results['Mode']."</td> <td>".$results['CITY']."</td></tr>";
            }
        }
        else{ 
            echo "<tr align='center' bgcolor='#fdee03'><td colspan='2' height='25px'>Sorry..not found in system you may Add it now Click Here</td><tr>"; 
   echo "</table>";  
        }   
    }
    else{ 
        echo "<tr align='center' bgcolor='#fdee03' font size='10'><td colspan='2' height='25px'>Your search keyword contains letters only ".$min_length;
    }
?>

line 20 from else:

else 
{ 
            echo "<tr align='center' bgcolor='#fdee03'><td colspan='2' height='25px'>Sorry..not found in system you may Add it now Click Here</td><tr>"; 
   echo "</table>";  
        }   

You should read ( and understand) the code before you past it. Why you kept the var_export($results) , don't you want to do something with the results ? … Did you first var_export results to understand the structure of the array (although in my comments is clear) and then use it? Why you keep using mysql_fetch_array ? If you don't understand something ask.
Your indent style is not working , also I guess that you are not using any IDE of any kind , otherwise you should have seen it before even testing.
In line 14 you have a Left Curly Bracket { so you open something … what ? In Line 16 you open again something (forget mysql_fetch_array ) .. in line 18 you close one and in line 19 you close the other. So what is doing that else in line 20.
I will repeat myself once more don't copy paste code without understanding even the basics, if you don't understand something ask and we will help if we can and understand what you are asking.

what im missing now

Member Avatar for diafol

what im missing now

Well, as jkon states, try to understand the logic here. You have a control structure - conditional branches without any conditional statement (if) on line 14.

i alrady define the condition at else, is it caused by css or what ? can u give me any exp?

Member Avatar for diafol

You don.t have an opening if statement

commented: Houston, we have a problem +9
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.