Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ke-boo
Starting Member
2 Posts |
Posted - 2008-04-28 : 00:47:18
|
| I am pretty new to this and hope someone can help and I hope I can explain my problem.I have a php form<form action="cpesearch.php"> State: <select name="stname"> <option value ="ALL">all states</option> <option value ="vic">VIC</option> <option value ="sa">SA</option>etc etc etcI am then connecting to my datatbase, assign the variables and doing the SQL query.if ($dbc = mysql_connect ('localhost','root','')) { if (@mysql_select_db('database')) { $sname = $_GET['stname']; $pname = $_GET['prname']; $sql = 'SELECT * FROM `cpe` WHERE eventdate >= CURDATE() AND state = \''.$sname.'\' AND presenter = \''.$pname.'\' ORDER BY eventdate ASC'; $r = mysql_query($sql) or die("Query failed".mysql_error($dbc)); while ($row = mysql_fetch_array($r)) { print "<div id=\"mainContent\"> <p>".$row['state']."</p>". "<p>".$row['eventdate']."</p>". "<p>".$row['eventtitle']."</p>".etc etc etcSo my problem is... I have an events table with presenters and state (and other info). I want to be able to select each presenter and state or all presenters and/or states. Not sure then how to pass the variable into my sql statement if they want to select ALL. |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2008-04-28 : 06:31:27
|
| Is this mysql? If so, you'll have more success on a different forum since this is for Microsoft SQL Server.Try: http://forums.mysql.com/Ryan Randall Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
ke-boo
Starting Member
2 Posts |
Posted - 2008-04-29 : 01:22:17
|
| Thanks - I was going to ask that question. I thought it was strange that no-one responded so thought I might have the wrong forum.Anyhow geek boyfriend worked it out for me last night with just a couple of if statements excluding 'all' - simple really.Thanks for the link - I will keep it for my next question. |
 |
|
|
|
|
|