0

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;
    }
?>

Edited by spluskhan

3
Contributors
9
Replies
39
Views
1 Year
Discussion Span
Last Post by diafol
0

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

0

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;
    }
?>
0

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>";  
        }   
1

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.

0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.