Update on my needs :-)
Posted: Sat Oct 02, 2004 8:36 am
feyd | Please use
The problems I am having though revolve around to things. The first being the part in the code where it says $value the second time it should use the value from the URL that is being used ie.
but at the moment it is just using the same value of colour so that would be my first question and then secondly when it is looping through is is adding the " AND " to the end of each criteria but it then obviously adds it to the end of the last criteria aswell like this :
so I would like to be able to somehow get rid of the last AND.
Really what I need is to be able to send in a URL in this format :
and then be able to create this SELECT query :
but I just can't seem to get it working.
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 :
at the end of the PHP file so that it creates a valid SELECT query as I have created a field called emptyField in the database with no data in it.
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]
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]