Jump to content

No input All results


newjaguar

Recommended Posts

How can I make sure this query do not show all result.

 

If input is empty it should show NO results.

 

I do not want to use java.

 

Thanks for your help in advance.

<?php
//
//
$search=stripslashes($_POST["Last_Name"]);
$search1=stripslashes($_POST["First_Name"]);

if ($search == '' && $search1 == '') {

$search=stripslashes($_GET["fname"]);
$search1=stripslashes($_GET["lname"]);

}
//

// Retrieve all the data from the "example" table
$result = mysql_query("SELECT * FROM example WHERE last LIKE '%$search%' AND first LIKE '$search1%' LIMIT $offset, $rowsPerPage ")or die(mysql_error());
//
?>

Link to comment
https://forums.phpfreaks.com/topic/113303-no-input-all-results/
Share on other sites

If input is empty it should show NO results.

 

<?php

if(isset($_POST['Last_Name']) && isset($_POST['First_Name'])) {

  $search = trim($_POST['Last_Name']);

  $search1 = trim($_POST['First_Name']);

} else {

  $search = trim($_GET['Last_Name']);

  $search1 = trim($_GET['First_Name']);

}

 

if(!empty($search) && !empty($search1)) {

  ... // do whatever you want since this is not empty

}

 

// whatever else you want to do

?>

Link to comment
https://forums.phpfreaks.com/topic/113303-no-input-all-results/#findComment-582151
Share on other sites

Thanks for the reply..

 

I forgot to mention I have NO php knowledge.. somehow I pieced this together.

Can you please help me fix this. If no name is entered or there is no match I want to display "No records found" and do not want to display prev and next page either.

 

Thanks for helping in advance.

 

<?php
//
if(isset($_POST['Last_Name']) && isset($_POST['First_Name'])) {
  $search = trim($_POST['Last_Name']);
  $search1 = trim($_POST['First_Name']);
} else {
  $search = trim($_GET['Last_Name']);
  $search1 = trim($_GET['First_Name']);
}

if(!empty($search) && !empty($search1)) {
// do whatever you want since this is not empty
}

// whatever else you want to do
}
//
// how many rows to show per page
$rowsPerPage = 5;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

// 
// Retrieve all the data from the "example" table
$result = mysql_query("SELECT * FROM example WHERE last LIKE '%$search%' AND first LIKE 

'$search1%' LIMIT $offset, $rowsPerPage ")or die(mysql_error());
//
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $row['last'];
echo "</td><td>"; 
echo $row['first'];
echo "</td><td>"; 
echo $row['phone'];
echo "</td></tr>"; 
}
//
// how many rows we have in database
$numresults = mysql_query("SELECT * FROM example WHERE last LIKE '%$search%' AND first LIKE 

'$search1%'")or die(mysql_error());
$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
//
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

$self = $_SERVER['PHP_SELF'];

// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link

// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page&fname=$search&lname=$search1\">[Prev]</a> ";

$first = " <a href=\"$self?page=1&fname=$search&lname=$search1\">[First Page]</a> ";
} 
else
{
$prev  = ' [Prev] ';       // we're on page one, don't enable 'previous' link
$first = ' [First Page] '; // nor 'first page' link
}

// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page&fname=$search&lname=$search1\">[Next]</a> ";

$last = " <a href=\"$self?page=$maxPage&fname=$search&lname=$search1\">[Last Page]

</a> ";
} 
else
{
$next = ' [Next] ';      // we're on the last page, don't enable 'next' link
$last = ' [Last Page] '; // nor 'last page' link
}

// print the page navigation link
//echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> 
//
//pages " . $next . $last;
echo "<tr><td colspan=3>";
echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> 

pages " . $next . $last;
echo "</td></tr>";
//
//
?>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/113303-no-input-all-results/#findComment-582429
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.