List:General Discussion« Previous MessageNext Message »
From:Jasper Bryant-Greene Date:September 18 2005 4:31am
Subject:Re: Select ALL rows with WHERE statement
View as plain text  
Alvaro Cobo wrote:
> Thanks Pooly and Peter:
> 
> The problem is that in the same php page I would like to choose either the
> calculation from an especific year or the calculation from the whole table
> using URL.

The same page can easily handle both.

<?php
$sql = "SELECT * FROM mytable";

if(isset($_GET['year']) && !empty($_GET['year'])) {
	$sql .= " WHERE year=" . intval($_GET['year']);
}

$result = mysql_query($sql);
?>

If year is passed as a GET variable then it will retrieve only records 
with that year in the table. If it's not passed then it will retrieve 
the whole table by omitting the WHERE clause.

-- 
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/
Thread
Select ALL rows with WHERE statementAlvaro Cobo17 Sep
  • Re: Select ALL rows with WHERE statementPooly17 Sep
  • Re: Select ALL rows with WHERE statementPeter Brawley17 Sep
  • Re: Select ALL rows with WHERE statementAlvaro Cobo18 Sep
    • Re: Select ALL rows with WHERE statementJasper Bryant-Greene18 Sep
      • Re: Select ALL rows with WHERE statementPooly18 Sep
    • Re: Select ALL rows with WHERE statementPeter Brawley18 Sep