Reply
Database query
Old 01-15-2005, 04:46 PM Database query
Average Talker

Posts: 29
Currently I am installing a real estate search script on my website and am having a few problems.

I am trying to ad a text field search for it, and when I create a query that includes:

PropertyRef = $PropertyRef and do a search without entering a number, it displays and error on the query. It works otherwise, but I need to find a way to be able to search without entering in any info into the text field.

Here is a link to where search_.php is located for further reference:
www.assertivead.com/propertyplus

Would I need to somehow cancel the PropertyRef if the contents "PropertyRef" == "" or something along that lines?
WDavis is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 01-15-2005, 05:35 PM
Marvin Le Rouge's Avatar
Skilled Talker

Posts: 52
Hi,

I suppose your query looks something like "select ... from ... where propertyref = $propertyref"
When propertyref is empty, it gives "where propertyref = ", which is illegal in sql. The condition using propertyref should not be in the query if propertyref doesn't have a value.
Marvin Le Rouge is offline
Reply With Quote
View Public Profile
 
Old 01-15-2005, 06:00 PM
Average Talker

Posts: 29
if that is the case, what can I do to get around that and make it legal?

Could I put a die on the PropertyRef somehow?

Last edited by WDavis : 01-15-2005 at 06:43 PM.
WDavis is offline
Reply With Quote
View Public Profile
 
Old 01-15-2005, 06:43 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Use php to dynamically assemble your query string:

PHP Code:

if(!empty($propertyref)) $propertyref " WHERE propertyref = '".$propertyref."'";

$result mysql_query("SELECT stuff FROM table".$propertyref); 
That way if propertyref is empty, you get "SELECT stuff FROM table"
If it has a value, say propertyref is 87, it gets set to be 'propertyref=87', and the query gets a where clause.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';
Scribble Pad MOD for phpBB (aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 01-15-2005, 08:00 PM
Average Talker

Posts: 29
I am not exactly sure on how to implement that, but could I use part of the function and say someting like

if (!empty($PropertyRef)) {$result = mysql_query("SELECT * FROM $property_table WHERE PropertyRef = $PropertyRef"); }

that seemed to take care of my problem! Thanks for the insight, wouldn't have gotten it without your help

Last edited by WDavis : 01-15-2005 at 08:05 PM.
WDavis is offline
Reply With Quote
View Public Profile
 
Old 01-16-2005, 06:36 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Yeah I think that would achieve the same effect.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';
Scribble Pad MOD for phpBB (aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 01-17-2005, 12:02 PM
Average Talker

Posts: 29
I got that to work, but I had to implement a die in order to stop it from listing the page number script. Without it, it says that it had found 13 properties. The only problem is with the die in place, it also cancels the footer include on that page the search is included into (ie search.php has footer.php and search_.php included into the template).

What could I do to set this up so it won't cancel that footer? I have tried a few other functions, but they all either return errors or do the smae thing.

Thnaks!
WDavis is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Database query
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14231 seconds with 12 queries