Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Variables, how to display only one at a time? 1

Status
Not open for further replies.

PaulinKC

Programmer
Apr 2, 2002
50
US
I've got a problem with a page that I'm trying to create. What I am wanting to do is have 2 links that display the results of a sql query based on which one was clicked.

The first link would only display the current months news items and the second would display all news items.

Here's my php code so far in index.php

<?php

$user = &quot;username&quot;;
$pass = &quot;pass&quot;;
$db = &quot;database&quot;;
$link = mysql_connect (&quot;localhost&quot;, &quot;username&quot;, &quot;pass&quot;) or die (&quot;I cannot connect to the database because: &quot;.mysql_error() );

if ( ! $link )

die( &quot;Couldn't connect to the database&quot; );

mysql_select_db ( $db )

or die( &quot;Couldn't open $db: &quot;.mysql_error() );


$Query = &quot;select * from tblNews where extract(YEAR_MONTH from newsDate) = extract(YEAR_MONTH from CURRENT_DATE)&quot;;
$Query2 = &quot;select * from tblNews Order By newsDate DESC&quot;;

$result = mysql_query($Query, $link);
$result2 = mysql_query($Query2, $link);

?>

How would I format the URL to retrieve $result if I only wanted the current months news items and vice versa?
 
Create a page like:

<body>
<a href=&quot;thescript.php?query=1>first</a>
<a href=&quot;thescript.php?query=2>second</a>
</body>

Then in the script that produces the output, do something like:

connect to database;
select db;

switch ($_GET['query'])
{
case 1:
$query = first query;
break;
case 2:
$query = second query;
break;
}

perform query $query;

display output.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Thanks for your help!! Worked with no problems!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top