Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hi there,
Just a quick update. It was me being silly! I managed to find a way to do partially what I wanted.
The code I am using is this :Code: Select all
<?
$queryStart = "SELECT * FROM myDatabaseTable WHERE ";
echo $queryStart;
// Open our connection to the database....
$dbh = mysql_connect("localhost", "userName", "password");
mysql_select_db("databaseName");
// Set our query....
$sql = "SELECT * FROM myDatabase";
$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)) {
$output = $value . " LIKE " . $value . " AND ";
echo $output;
}
}
// increment $count by 1
$count++;
}
?>Code: Select all
http://www.mySite.com/searchDatabase.php?colour=redCode: Select all
"SELECT * FROM myDatabaseTable WHERE colour = colour AND type = type AND length = length AND"Really what I need is to be able to send in a URL in this format :
Code: Select all
http://www.mySite.com/searchData.php?colour=red&type=wooden&length=longCode: Select all
"SELECT * FROM myDatabaseTable WHERE colour LIKE 'red%' AND type LIKE 'wooden%' AND length LIKE '$long%'"Any help with this would be massively appreciated.
EDIT
I managed to (I think) to fix the one problem by placing this line of code :
Code: Select all
echo "emptyField IS NULL";Could you let me know if this will create any problems seeing as how there isn't a field with that name when it comes to searching the database?
I still have the other problem though of passing in the values to the script.
Regards,
Mark Bowen
feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]