You'll need to check whether month is set and if so use the month & year query and if not just query on the year.
I don't think it's reasonably doable in a single statement.
i.e.
if ($month != "") {
$sql="SELECT * FROM weight WHERE month='$month' & year='$year';
} else {
$sql="SELECT * FROM weight WHERE year='$year'";
}
(although someone may well have a cleverer solution)
$sql="SELECT * FROM weight WHERE year='$year'"; if ($month != "") $sql .= "AND month='$month'";
SELECT * FROM weight WHERE month='August' AND year='2010' OR year='2010'
SELECT * FROM weight WHERE year='2010'
SELECT * FROM weight WHERE (month='August' AND year='2010') OR year='2011'
if (isset($_GET['month'], $_GET['year'])) { $month = mysql_escape_string($month); $year = mysql_escape_string($year); $sql = "SELECT * FROM weight WHERE month = '$month' AND year = '$year'"; } else if (isset($_GET['month'])) { $month = mysql_escape_string($month); $sql = "SELECT * FROM weight WHERE month = '$month'"; } else if (isset($_GET['year'])) { $year = mysql_escape_string($year); $sql = "SELECT * FROM weight WHERE year = '$year'"; } $result = mysql_query($sql);
<input type="text" id="year" value="Enter Year"/> <button type="button" onclick="location.href='./date.php?year='+document.getElementById('year').value;">Go To</button></div>
<input type="text" id="month" value="Enter Month"/> <input type="text" id="year1" value="Enter Year"/> <button type="button" onclick="location.href='./date.php?month='+document.getElementById('month').value'&year='+document.getElementById('year1').value;">Go To</button
What's this mysql_escape_string chap and what does it do for me?
(As I'm sure you're aware you code works perfectly well also :D )
<form action="./date.php" method="get"> <input type="text" id="year" name="year" value="Enter Year" /> <button type="submit">Go To</button> </form> <form action="./date.php" method="get"> <input type="text" id="month" name="month" value="Enter Month/> <input type="text" id="year1" name="year" value="Enter Year" /> <button type="submit">Go To</button> </form>
<form method="get" action="date.php"> <input name="month" type="text" value="Enter month" /> <input name="year" type="text" value="Enter year" /> <button type="submit">Go To</button> </form>
I see, yeah I guess I should be using escapes then.
Fantastic stuff, I can now be a sad bastard and track my weight via a pretty(ish) graph (using PHPGraphLib).
image1.jpg,image2.jpg,image3.jpg,image4.jpg
{$row[images]}
<img src="image1.jpg" /><img src="image2.jpg" /><img src="image3.jpg" /><img src="image4.jpg" />