Jump to content

SQL Query if variables exist


jacko_162

Recommended Posts

i have a page that gets variables to make a query.

 

what i wanted help with is:

 

the page can be viewed without variables in the URL, if this is the case i want to run a different SQL query.

 

can someone help me with what coding i need for an if statement to check if variables exist in the URL if they do run a sql comand and if not run other sql command.

 

 

here is my coding;

 

Viewing Results Between: <strong><span class="time"><?php
$start = $_GET['graph_start'];
if ($start)
{
echo "$start";
}
else
{
echo "$oldDate";
} ?></span></strong>
- <strong><span class="time">
<?php
$end = $_GET['graph_end'];
if ($end)
{
echo "$end";
}
else
{
echo "$todaydate";
} ?></span></strong>
                                                            <br />
                              </form> </td>
                            </tr>
                            <tr>
                              <td colspan="2" valign="top"><?php

function imp($char,$tag){
foreach($char as $key=>$value){
$char[$key] = $value;
}
$char = implode($tag,$char);
return $char;
}

$sql = "SELECT * FROM `tests` WHERE date <= '$end' AND  date >= '$start' AND member_id = '1' ORDER BY ID ASC LIMIT 0,10";

$query = mysql_query($sql);
while($row = mysql_fetch_array($query)){
$date[] = $row[date];
$day[] = $row[day];
$test1[] = $row[test1];
$test2[] = $row[test2];
$test3[] = $row[test3];
$test4[] = $row[test4];
$test5[] = $row[test5];
$test6[] = $row[test6];
$test7[] = $row[test7];
$test8[] = $row[test8];
$test9[] = $row[test9];
$test10[] = $row[test10];
$test11[] = $row[test11];
$test12[] = $row[test12];
$test13[] = $row[test13];
$test14[] = $row[test14];
}

?>

 

variable URL will be something like this;

 

test.php?graph_start=2009-11-09&graph_end=2010-05-09

Link to comment
https://forums.phpfreaks.com/topic/201183-sql-query-if-variables-exist/
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.