PHP and MySQL ....dynamic query?

From: Date: Mon, 05 Mar 2001 22:34:59 +0000
Subject: PHP and MySQL ....dynamic query?
Groups: php.general 
Request: Send a blank email to php-general+get-42681@lists.php.net to get a copy of this message
Hello everyone. :) I am attempting to construct a query with PHP and MySQL based on user input from a referring form page. Here is an example of what I need this to do: This will involve multiple variables, but I will just use 2 here: if ($dig== "1") { $qual1 = "WHERE (track >= 0)"; } if ($dig== "2") { $qual1 = "WHERE (track >= 0) AND (track <=100)"; } if ($lot == "1") { $qual2 = "AND (acres >= 100)"; } if ($lot == "2") { $qual2 = "AND (acres >= 500) AND (acres <= 650)"; } // create SQL statement $sql = "SELECT * FROM myTable $qual1 $qual2"; // execute SQL query and get result $sql_result = mysql_query($sql,$connection) or die("Could not execute the query"); ..... You can see my problem here. I want to be able to write parts of my sql statement based upon user input, and then execute it all at once. How do I tie all of my $qual variables in so that this will read/execute it properly? Thanks :)

« previous php.general (#42681) next »