Page 2 of 2

Re: Search result hyperlink not working

Posted: Mon Mar 31, 2008 11:02 am
by khushbush
FYI, this is the error I keep getting:

Warning: Cannot modify header information - headers already sent by (output started at C:\Documents and Settings\Desktop\Project\searchprocess.php:7) in C:\Documents and Settings\Desktop\Project\searchprocess.php on line 33

Re: Search result hyperlink not working

Posted: Mon Mar 31, 2008 2:26 pm
by khushbush
Ok...one other thing with regards to the search function...I want to search for all types of properties within a certain area of London in my search function, but unfortunately, it doesn't seem to work. It keeps coming up with "There are no records returned for your search query.", which is an indication of the failure of the function.

Here is the code for that query:

Code: Select all

 
<?
//select the table
if($_POST['propertyType']=="No Preference" && $_POST['postcode']){
$result = mysql_query("SELECT * FROM property WHERE propertyArea = '$_POST[postcode]' ORDER BY `propertyID` ASC");
 
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>
 
<tr>
<td>
<font face="Arial" color="#0B3A62">
<?
// Echo them out
   echo "<a href=\"searchprocess.php?id=$row[propertyID]\">$row[propertyType]". ", £". $row[propertyPrice];
   }
   }
 
   ?>
 

Re: Search result hyperlink not working

Posted: Mon Mar 31, 2008 4:23 pm
by kryles
The header warning is you cannot use start_session() or setcookie() once you have sent something to the screen (anything in HTML, an echo or a print in php).

The other part:

Code: Select all

 
....`propertyID` ASC"
 
not sure how PHP reacts to backticks, use single quotes instead.

Code: Select all

 
echo '<a href="searchprocess.php?id='.$row["propertyID"].'">'.$row["propertyType"].', £'.$row["propertyPrice"];
 
im not sure if you have to, but use quotes inside the $row[ ], I don't think it matters which quote but I use the above method usually

Re: Search result hyperlink not working

Posted: Mon Mar 31, 2008 6:09 pm
by khushbush
Changing the backticks to single quotes didn't work for some reason...

It's really weird...I know this query is supposed to work...but it isn't... :?

Re: Search result hyperlink not working

Posted: Mon Mar 31, 2008 6:26 pm
by s.dot
You must use the link shown two posts above to concatenate in the variables in the URL.

Re: Search result hyperlink not working

Posted: Mon Mar 31, 2008 7:00 pm
by khushbush
The URL isn't the problem...

The problem lies in the SQL query in the code four posts up...
Thanks in advance, Scottayy... :)

Btw, thank you so much to kryles for being a MAJOR help over these past coupla days! This is actually my final-year dissertation...and if I get a good mark in this, part of the credit will be given to you for helping me :D

Re: Search result hyperlink not working(SOLVED)

Posted: Tue Apr 01, 2008 5:31 am
by khushbush
I solved the search query!!

Code: Select all

 
<?
//select the table
if(!$_POST['propertyType']=="House" && !$_POST['propertyType']=="Flat" && !$_POST['propertyType']=="Bungalow" && $_POST['postcode']){
$result = mysql_query("SELECT * FROM property WHERE propertyArea = '$_POST[postcode]' ORDER BY 'propertyID' ASC");
 
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>
 
<tr>
<td>
<font face="Arial" color="#0B3A62">
<?
// Echo them out
   echo "<a href=\"searchprocess.php?id=$row[propertyID]\">$row[propertyType]". ", £". $row[propertyPrice];
   }
   }
 
   ?>
 

Re: Search result hyperlink not working

Posted: Tue Apr 01, 2008 7:25 am
by kryles
was I right with the backticks instead of the single quote?

Re: Search result hyperlink not working

Posted: Tue Apr 01, 2008 10:45 am
by khushbush
Erm...unfortunately not...sorry kryles! :)

It was just something to do with if statement conditions...but it works...yay! :D

Ok...some more problems... :x ...they keep on coming!

This is a different kinda search...advanced search...need to search for properties within a specific search criteria specified by price as well as property type:

Code: Select all

 
<?
//select the table
if(!$_POST['propertyType']=="House" && !$_POST['propertyType']=="Flat" && !$_POST['propertyType']=="Bungalow" && !$_POST['postcode'] && $_POST['propertyPriceMin'] && $_POST['propertyPriceMax']){
$result = mysql_query("SELECT * FROM property WHERE propertyPrice BETWEEN '$_POST[propertyPriceMin]' AND '$_POST[propertyPriceMax]' ORDER BY 'propertyID' ASC");
 
 
Now...I think it might be a problem with the HTML form...OR a problem with the query...but I'm not quite sure. I'm gonna keep checking. In the meantime, if anyone can see where I've gone wrong, then please do not hesitate to let me know on this thread! :)

Re: Search result hyperlink not working

Posted: Tue Apr 01, 2008 12:23 pm
by kryles
echo out the $_POST[ ] variables to see if you are getting what you expect from the form

Re: Search result hyperlink not working

Posted: Tue Apr 01, 2008 2:28 pm
by John Cartwright
simpler than echo'ing arrays, use var_dump(), or print_r()

Code: Select all

echo '<pre>'. print_r($_POST, true) .'</pre>';