Thanks to the absolutely excellent help from two people on this board I more or less now have everything working the way I need it but I just have one more small question.
Sorry for posting this in a new post as I wasn't sure if anyone was getting my replies to the original post as it now has [SOLVED] in front of it.
What I have is a piece of code (generously given to me by the aforementioned people) which takes a database table, returns all the field names and definitions so that I can use this data from within a Flash movie to build a load of checkboxes. I then want to be able to click on a button and send a search string to a PHP file such as :
http://www.mySite.com/search.php?colour ... ength=long
and use these variables to search a database table. This can all be done I know but what I really want to do is not have to write out the code for every single field I am checking against.
The code I have so far is this below :
Code: Select all
<?
$queryStart = "SELECT * FROM myDatabaseTable WHERE ";
// Open our connection to the database....
$dbh = mysql_connect("localhost", "userName", "password");
mysql_select_db("myDatabase");
// Set our query....
$sql = "SELECT * FROM myTable";
$result = mysql_query($sql) or die(mysql_error());
// Set up a $count variable....
$count = 0;
// create an array with field names we don't want to output
$excluded_fields = array('id', 'name');
while ($row = mysql_fetch_assoc($result)){
foreach ($row as $key => $value) {
// check that the $key (the field name) isn't listed in the $excluded_fields
// array so we only output fields we want
if (!in_array($key, $excluded_fields)) {
// PART I AM HAVING TROUBLE WITH IS BELOW
$output = $value . " LIKE " . '$value' . " AND ";
// END TROUBLE !!
$queryMiddle .= $output;
}
}
// increment $count by 1
$count++;
}
$queryEnd = "emptyField IS NULL";
$databaseQuery = $queryStart.$queryMiddle.$queryEnd;
echo "<b>Database Query - </b><br><br>" .$databaseQuery;
echo "<br><br>";
echo "<b>Results -</b><br><br>";
// ****************************************************************************/
// PART TWO
// USE OUR QUERY TO QUERY ANOTHER TABLE
$sql = $databaseQuery;
$result = mysql_query($sql) or die(mysql_error());
// Set up a $count variable....
$count = 0;
// create an array with field names we don't want to output
$excluded_fields = array('fieldOne', 'fieldTwo');
while ($row = mysql_fetch_assoc($result)){
foreach ($row as $key => $value) {
// check that the $key (the field name) isn't listed in the $excluded_fields
// array so we only output fields we want
if (!in_array($key, $excluded_fields)) {
$output = $key.$count.'='.$value . "&";
echo $output;
}
}
// increment $count by 1
$count++;
}
?>If anyone can help me with this then I would be exceptionally greatful.
Regards,
Mark Bowen