Question

problem with PHP limit page and header("Location:

Asked by: satmanuk

Hi all,

I am having a problem with a php page im working on.
The page is a results page from a keyword search page.

On this page i limit the records to 10 and have page numbers so the user can click on the page they want records for.

I also have a  script at the top of the page that directs the user back to the search form and echos a message if no fields are filled in and the search is submitted.

The problem i have is if i click one of the page numbers  to view records on that recordset page, the page doesnt load, instead the header code at the top of my page is executed. and i get redirected to the search form as if i just entered a blank search?
I assume this is due to the way i have my code laid out but i am unsure how to fix the issue while retaining my header script at the top of the page.

Here is my entire page code so you can see what i am reffering to.

<?php require_once('Connections/EE_con.php'); ?>
<?php

$keyword_street = "";
$keyword_village = "";
$case = 0;
if(!isset($_REQUEST["keyword_street"]) || $_REQUEST["keyword_street"]=='')
{
      $keyword_street = "<font color=\"red\">Please enter this field!</font>";
}

if(!isset($_REQUEST["keyword_village"]) || $_REQUEST["keyword_village"]=='')
{
      $keyword_village = "<font color=\"red\">Please enter this field!</font>";
}
     
if($keyword_village!="" && $keyword_street!="")
{
      header("Location: keyword2.php?street=$keyword_street&village=$keyword_village");
      // Keyword2.php is the name of the page where my search form is.
     exit();
}
?>

<?

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;


mysql_select_db($database_EE_con, $EE_con);

$keywordstreet = $_REQUEST['keyword_street'];
$keywordvillage = $_REQUEST['keyword_village'];
$K_street = $_POST['keyword_street'];
$K_village = $_POST['keyword_village'];



if (strlen($_POST['keyword_street']) > 0) {
$test = "one";
}
if (strlen($_POST['keyword_village']) > 0) {
$test2 = "two";
}

if ($test = "one" && $test2 = "two") {
$where_clause = "WHERE property_address1 LIKE '%$keywordstreet%' AND property_towncity LIKE '%$keywordvillage%'";
   }

$query_Recordset1 = "SELECT * FROM properties $where_clause ORDER BY price ASC";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $EE_con) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;



if ($totalRows_Recordset1 == 0){




echo "There are no results matching your search criteria <BR> Keyword 1:$K_street <BR> Keyword 2:$K_village <BR><BR> Click Here to search again!";
}

echo "whereclause:$where_clause<br>";
echo "keyword Street: $keywordstreet<br>";
echo "keyword Village: $keywordvillage<br>";
echo "test: $test<br>";
echo "test2: $test2<br>";
   do {

   ?>
   
 
    <p><?php echo $row_Recordset1['property_numname']; ?></p>
    <p><?php echo $row_Recordset1['property_address1']; ?></p>
    <p><?php echo $row_Recordset1['property_address2']; ?></p>
    <p><?php echo $row_Recordset1['property_towncity']; ?></p>
    <p><?php echo $row_Recordset1['prop_postcode']; ?></p>
    <p><?php echo $row_Recordset1['pic1']; ?></p>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

Page           <?php for ($i = 0; $i <= $totalPages_Recordset1; $i++) {
  $href = sprintf('%s?pageNum_Recordset1=%d%s', $currentPage, $i, $queryString_Recordset1);
  $label = $i + 1;
  echo '<a href="'.$href.'">'.$label.'</a>';
}
?>

<?php
mysql_free_result($Recordset1);
?>

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-11-13 at 15:05:15ID22958700
Tags

php

,

limit

,

header

,

location

Topic

PHP Scripting Language

Participating Experts
10
Points
500
Comments
25

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. include in die
    hello there, is there anyway i can have in die ("you need to have 5 points"); and include something like include ("help.html"); ??? thanks for any help!
  2. PHP MySQL Pagination
    I have a problem with pagination on my message board. The same page (i.e. page 1 containing the first 5 messages) appears each time I click on the "next page" link at the bottom. The URL is re-written to page=2 etc. but the same data is displayed even though I hav...
  3. Is there a way to redirect on "die"?
    Currently, I have a page set up for a "die" : $ext = strrchr($file_name,'.'); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { die("The file you are uploadingo./ doesn't have the correct extension."); } etc. Instead of die ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: hieloPosted on 2007-11-13 at 15:19:41ID: 20276265

These:
if(!isset($_REQUEST["keyword_street"]) || $_REQUEST["keyword_street"]=='')
{
      $keyword_street = "<font color=\"red\">Please enter this field!</font>";
}

if(!isset($_REQUEST["keyword_village"]) || $_REQUEST["keyword_village"]=='')
{
      $keyword_village = "<font color=\"red\">Please enter this field!</font>";
}
make sure that $keyword_village and $keyword_street always contain some value. Thus,
if($keyword_village!="" && $keyword_street!="")
will always be true an the header function will execute

 

by: satmanukPosted on 2007-11-13 at 15:29:44ID: 20276345

I get that but what i don't get is why they don't have a value. If they didn't then i wouldn't be seeing my results in the first place?

 

by: hieloPosted on 2007-11-13 at 15:35:26ID: 20276387

> why they don't have a value
you are wrong! you are checking the variables
$keyword_village  && $keyword_street
and you are always setting a value for them. By the time the script "hits" the if, neither of those variables is empty!

 

by: hieloPosted on 2007-11-13 at 15:38:21ID: 20276412

Try this:
if((!isset($_REQUEST["keyword_street"]) || $_REQUEST["keyword_street"]=='') && (!isset($_REQUEST["keyword_village"]) || $_REQUEST["keyword_village"]=='') )


instead of:
if($keyword_village!="" && $keyword_street!="")

 

by: satmanukPosted on 2007-11-13 at 15:51:43ID: 20276531

I replaced the line with your code but nothing changes.

 

by: steelseth12Posted on 2007-11-13 at 16:00:57ID: 20276597

try this

if(!isset($_GET['pageNum_Recordset1']) {
      
      if(!isset($_REQUEST["keyword_street"]) || $_REQUEST["keyword_street"]=='')
      {
              $keyword_street = "<font color=\"red\">Please enter this field!</font>";
      }
      
      if(!isset($_REQUEST["keyword_village"]) || $_REQUEST["keyword_village"]=='')
      {
              $keyword_village = "<font color=\"red\">Please enter this field!</font>";
      }
             
      if($keyword_village!="" && $keyword_street!="")
      {
              header("Location: keyword2.php?street=$keyword_street&village=$keyword_village");
              // Keyword2.php is the name of the page where my search form is.
             exit();
      }

}

 

by: satmanukPosted on 2007-11-13 at 16:04:14ID: 20276624

I get this when i run a search
Parse error: syntax error, unexpected '{' in /home/melvin/public_html/estateagents/keywordresults.php on line 7

 

by: steelseth12Posted on 2007-11-13 at 16:06:09ID: 20276641

forgot a ) .. sorry

if(!isset($_GET['pageNum_Recordset1'])) {
      
      if(!isset($_REQUEST["keyword_street"]) || $_REQUEST["keyword_street"]=='')
      {
              $keyword_street = "<font color=\"red\">Please enter this field!</font>";
      }
      
      if(!isset($_REQUEST["keyword_village"]) || $_REQUEST["keyword_village"]=='')
      {
              $keyword_village = "<font color=\"red\">Please enter this field!</font>";
      }
             
      if($keyword_village!="" && $keyword_street!="")
      {
              header("Location: keyword2.php?street=$keyword_street&village=$keyword_village");
              // Keyword2.php is the name of the page where my search form is.
             exit();
      }

}

 

by: satmanukPosted on 2007-11-13 at 16:18:25ID: 20276693

Ok cool cheers, The search works again and when i click the numbers it doesnt revert to the search page. but now when i click the page numbers the results screw up and show all in the table rather than the results based on my search? Example the results were 2 pages of records. I click page 2 and then the results display all records. So the search results are lost.

any ideas?

 

by: steelseth12Posted on 2007-11-13 at 16:29:51ID: 20276725

try this

$keywordstreet = $_REQUEST['keyword_street'];
$keywordvillage = $_REQUEST['keyword_village'];
$K_street = $_POST['keyword_street'];
$K_village = $_POST['keyword_village'];

$queryString_Recordset1 = "&keyword_street=".$_REQUEST['keyword_street']."&keyword_village=".$_REQUEST['keyword_village'];

if ($keywordstreet) {
$test = "one";
}
if ($keywordvillage) {
$test2 = "two";
}

 

by: satmanukPosted on 2007-11-13 at 17:04:14ID: 20276879

just wish i knew how you did that! it works!

Many thanks

i want to do something similar to  the header script for when a user searches something thats not found.
 at the moment i got this line:

if ($totalRows_Recordset1 == 0){
echo "There are no results matching your search criteria <BR> Keyword 1:$K_street <BR> Keyword 2:$K_village <BR><BR> Click Here to search again!";
}

Do you know if its possible to treat this the same as when a user trys to submit no data?

 

by: steelseth12Posted on 2007-11-13 at 17:13:26ID: 20276905

$queryString_Recordset1 = "&keyword_street=".$_REQUEST['keyword_street']."&keyword_village=".$_REQUEST['keyword_village'];

That just passes the search criteria to the next page.

 >> Do you know if its possible to treat this the same as when a user trys to submit no data?

You mean redirect the user back to the search page ?

 

by: satmanukPosted on 2007-11-13 at 17:45:58ID: 20277034

yes in essence what i want is the user to get a message on the searchform.php page saying no results found. like i have for when the form is submitted with no data.

Or instead of my code :
echo "There are no results matching your search criteria <BR> Keyword 1:$K_street <BR> Keyword 2:$K_village <BR><BR> Click Here to search again!";
}

have the user directed to a new page where i can state no results were found.

 

by: sandip132Posted on 2007-11-14 at 21:40:57ID: 20287126

 

by: cs97jjm3Posted on 2007-11-15 at 00:06:55ID: 20287549

 

by: ellandrdPosted on 2007-11-15 at 01:13:34ID: 20287742

Congratulations from ellandrd!!!

 

by: Klaatu01Posted on 2007-11-15 at 11:43:24ID: 20291743

Great to see a relatively new member with obviously valuable skills provide the 2 Millionth solution!  Well done!

 

by: Naser72Posted on 2007-11-18 at 13:18:27ID: 20309049

Well Done, and 2 Milions Congratulations :)

Regards,

Naser

 

by: kiranvjPosted on 2007-11-18 at 22:50:58ID: 20310640

Well done steelseth12 !!

 

by: satmanukPosted on 2007-11-21 at 11:57:04ID: 20330559

Thanks everyone! I was shocked to find that my question earnt me a laptop! i havent a clue what type it is? anyone know?

THANKS EXPERTS EXCHANGE!

 

by: kiranvjPosted on 2007-11-21 at 20:41:22ID: 20332609

>>i havent a clue what type it is?

from the EE newsletter

"Each laptop is outfitted with an Intel Core 2 Duo 2.0GHz processor, a 17-inch wide screen display, 2GB of memory, and dual 120GB hard drives. Our superb designers mocked up some flashy desktop wallpapers for the winners new laptops....."

congrats satmanuk!!

kiranvj

 

by: sandip132Posted on 2007-11-21 at 20:48:07ID: 20332631

These winners will also receive limited edition Experts Exchange 2,000,000 solutions shirts, and recognition in their member profiles as being part of EE history.

Cheers!

 

by: satmanukPosted on 2007-11-22 at 16:20:38ID: 20336770

COOL! thats a beast of a laptop!

:O) :O)

 

by: jinn_hnnlPosted on 2007-11-29 at 07:04:30ID: 20374045

I want to be this kind of winner :((
Great!
Welldone & congratz

 

by: sachindurgePosted on 2008-02-19 at 01:31:29ID: 20926832

gud one

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...