Search result hyperlink not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
khushbush
Forum Commoner
Posts: 99
Joined: Tue Mar 11, 2008 11:50 am

Re: Search result hyperlink not working

Post 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
User avatar
khushbush
Forum Commoner
Posts: 99
Joined: Tue Mar 11, 2008 11:50 am

Re: Search result hyperlink not working

Post 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];
   }
   }
 
   ?>
 
kryles
Forum Contributor
Posts: 114
Joined: Fri Feb 01, 2008 7:52 am

Re: Search result hyperlink not working

Post 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
User avatar
khushbush
Forum Commoner
Posts: 99
Joined: Tue Mar 11, 2008 11:50 am

Re: Search result hyperlink not working

Post 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... :?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Search result hyperlink not working

Post by s.dot »

You must use the link shown two posts above to concatenate in the variables in the URL.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
khushbush
Forum Commoner
Posts: 99
Joined: Tue Mar 11, 2008 11:50 am

Re: Search result hyperlink not working

Post 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
User avatar
khushbush
Forum Commoner
Posts: 99
Joined: Tue Mar 11, 2008 11:50 am

Re: Search result hyperlink not working(SOLVED)

Post 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];
   }
   }
 
   ?>
 
kryles
Forum Contributor
Posts: 114
Joined: Fri Feb 01, 2008 7:52 am

Re: Search result hyperlink not working

Post by kryles »

was I right with the backticks instead of the single quote?
User avatar
khushbush
Forum Commoner
Posts: 99
Joined: Tue Mar 11, 2008 11:50 am

Re: Search result hyperlink not working

Post 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! :)
kryles
Forum Contributor
Posts: 114
Joined: Fri Feb 01, 2008 7:52 am

Re: Search result hyperlink not working

Post by kryles »

echo out the $_POST[ ] variables to see if you are getting what you expect from the form
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Search result hyperlink not working

Post by John Cartwright »

simpler than echo'ing arrays, use var_dump(), or print_r()

Code: Select all

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