one more php question

P

Peter

ok, i am pulling data from a mysql database with php. ill
use an example for my question:

I have a table with first name,last name,year born. I want
a user to have a link to be able to search for people born
only in any one year. So i would have a link bar like this
on my page: "click here: 1980, 1981, 1982, etc.." Can i
set up my links in frontpage to search for that year only
and display the results right there on that php page. Or
would i have to have each year's link have its own page
and run a different php script to find for that specified
year?
 
T

Thomas A. Rowe

You should be able to create your link with the year as the lookup value and then pass that to a
single page that then uses the value to query the database.

I don't use PHP, but with ASP/VBScript it could be done like:

Link:
pagename.asp?yr=1980


Retrieve on pagename.asp:

<%
Dim yr
yr = request.querystring("yr")

SELECT * FROM tablename WHERE born = '" & yr & "' "
etc.
%>


--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
 
J

Jack Brewster

A PHP equivalent that allows you to use the same results page as you are
using now.

Link:
pagename.php?year=1980

<?php
// Set default query to select all records
$query = "SELECT * FROM table";

// Check if 'year' was passed as a parameter
if (isset($_GET['year']) {
// Refine query by appending WHERE clause
$query .= " WHERE year_born = " . $_POST['year'];
}

// Submit query using whatever method you are currently using
// Process and display results
?>

That code is off the top of my head, so no guarantees on syntax. But it
should put you in the ballpark. Right now, that code just checks for
whether or not year is passed, not whether it is a _valid_ year. You may
want to add a checking routine to validate the value is indeed a year and
not a word or some other invalid data and, if it is, either report an error
or just go back to the default query.

Good luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top