Page 1 of 2
Search result hyperlink not working
Posted: Sat Mar 29, 2008 12:28 pm
by khushbush
I need some help creating a search hyperlink for my web application...
I'm creating a search functionality, and I want the results to be displayed as hyperlinks, so that when users click on each result, they can view the details specific to that result.
I seem to be nearly there, as I've got the results to show up from the search page, as well as the hyperlinks, which then go onto another page to show the details of that result. However, I can't get the details to come up...
Lemme show you the code that I am using...
This is code from a file called quicksearch.php:
if($_POST['propertyType']=="House" && $_POST['postcode']){
$result = mysql_query("SELECT*FROM property WHERE propertyType = 'House' AND 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]";
}
}
?>
And this is code from a file called searchprocess.php:
if (isset($_GET['propertyID'])) {
// Put the value in a separate variable
$propID = mysql_real_escape_string($_GET['propertyID']);
$result = mysql_query("select * from property propertyPrice, propertyDescription, propertyArea where propertyID = $propID");
$desc = mysql_result($result,"propertyDescription");
while ($row = mysql_fetch_assoc($result)) {
echo $desc;
}
}
else {
die("No valid property specified!");
}
Where could I be going wrong? Please help!!
Re: Search result hyperlink not working
Posted: Sat Mar 29, 2008 2:36 pm
by deejay
Hi
Are you supposed to be using POST in the first page and then GET in the next. I would have thought you'd use one or the other.
Re: Search result hyperlink not working
Posted: Sat Mar 29, 2008 3:44 pm
by khushbush
Oh sorry, I didn't explain that.
I've used POST for the search form, so that when the user enters a particular string in the form, POST will be used to match the string exactly within the database. The search function works. I seem to be getting the results I need. Obviously, I will be adding addslashes to clean up the string...
I've used GET in the other page to refer to the property ID...unfortunately, it doesn't show the details that I want it to. It seems to be coming up with "No valid property specified!" as that is the message to be shown if the if function fails.
I have a feeling that the problem is to do with the if function and most likely GET...but I'm not quite sure
That's why I need help...cos I'm so close to getting it to do what I want it to do...and yet so far

Re: Search result hyperlink not working
Posted: Sun Mar 30, 2008 7:31 pm
by AMCH
The problem is that your $_GET is getting the wrong thing.
"id" is the name of the variable that you want to get based on the link as I have shown in red. propertyID is the value.
Replace the
if (isset($_GET['propertyID'])) { with:
if (isset($_GET['id'])) { and let me know if it works.
Code: Select all
// Echo them out
echo "<a href=\"searchprocess.php?[b][color=#FF0000]id[/color][/b]=$row[propertyID]\">$row[propertyType]";
}
}
//---------------------------
[color=#4000BF]if (isset($_GET['propertyID'])) {[/color]
// Put the value in a separate variable
$propID = mysql_real_escape_string($_GET['propertyID']);
$result = mysql_query("select * from property propertyPrice, propertyDescription, propertyArea where propertyID = $propID");
$desc = mysql_result($result,"propertyDescription");
while ($row = mysql_fetch_assoc($result)) {
echo $desc;
}
}
else {
die("No valid property specified!");
}
Hope this helps
Kind Regards
AMCH
Re: Search result hyperlink not working
Posted: Sun Mar 30, 2008 7:34 pm
by AMCH
Oh yea and in future guys can you please put code in <code> tags as it makes my head hurt trying to read it otherwise!
Thanks lol

Re: Search result hyperlink not working
Posted: Mon Mar 31, 2008 5:39 am
by khushbush
Thanks...
But now it keeps giving me the following errors:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\Desktop\Project\searchprocess.php on line 12
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\Desktop\Project\searchprocess.php on line 14
I am soooooooooo confused!

Re: Search result hyperlink not working
Posted: Mon Mar 31, 2008 7:56 am
by kryles
AMCH wrote:Oh yea and in future guys can you please put code in <code> tags as it makes my head hurt trying to read it otherwise!
Thanks lol

use
Code: Select all
tag to highlight stuff. It's prettier
Re: Search result hyperlink not working
Posted: Mon Mar 31, 2008 7:58 am
by kryles
Code: Select all
// Echo them out
echo "<a href=\"searchprocess.php?id=$row[propertyID]\">$row[propertyType]";
}
}
//---------------------------
if (isset($_GET['id'])) { //did you change this to look like this
// Put the value in a separate variable
$propID = mysql_real_escape_string($_GET['id']); //did you change this line to look like this
$result = mysql_query("select * from property propertyPrice, propertyDescription, propertyArea where propertyID = $propID");
$desc = mysql_result($result,"propertyDescription");
while ($row = mysql_fetch_assoc($result)) {
echo $desc;
}
}
else {
die("No valid property specified!");
}
Re: Search result hyperlink not working
Posted: Mon Mar 31, 2008 8:26 am
by khushbush
It still keeps showing me the abovementioned errors...
Anything else I could do?
Re: Search result hyperlink not working
Posted: Mon Mar 31, 2008 8:48 am
by kryles
Code: Select all
$query = "select * from property where propertyID = $propID";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
{
echo $row[0]; // $row[0] is just the first field in the table, $row[1] is the second etc etc
}
try this, see what you get and see if it is close to what you want.
The sql syntax seemed weird to me since it looked like you were naming off a bunch of tables....but I assumed these were supposed to be field names (covered by using the *).
Re: Search result hyperlink not working
Posted: Mon Mar 31, 2008 9:05 am
by khushbush
Thanks, that just about works!!
It outputted the property ID number...any idea as to how I should output the property details, such as price, area and description? Would I have to play around with the SQL query or would I need to echo SQL variables or both?
Re: Search result hyperlink not working
Posted: Mon Mar 31, 2008 10:04 am
by kryles
well if row[0] is property_id then row[1] will be the next field, and row[2] the next etc etc
Code: Select all
$query = "select * from property where propertyID = $propID";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
{
echo $row["propertyID"];
echo $row["propertyPrice"];
echo $row["propertyDescription"];
echo $row["propertyArea"];
//previously i had $row[0] which i think is faster when needed, but this way is more intuitive.
}
Just use echo $row["FIELDNAME"]; to display the result. Hopefully this works for you

Re: Search result hyperlink not working
Posted: Mon Mar 31, 2008 10:22 am
by khushbush
Thanks! I got it working another way before you posted...but the main thing is that I can get the search results up...thank you soooooooooooooooo much!!
Oh yes...one other query...how can I get an image up? Everytime I do that...it comes up in funny text. Should I be asking this question on another thread?
I've tried using MIME headers and they don't seem to work, because it doesn't show anything. I've stored images in my database as jpeg BLOBs.
I'm gonna repost the entire code for reference...
Code: Select all
<?
include "menu.php";?>
<HTML>
<BODY>
<BR>
<BR>
<BR>
<?
mysql_connect("******", "****", "*****") or die(mysql_error());
mysql_select_db("property") or die(mysql_error());
if (isset($_GET['id'])) {
// Put the value in a separate variable
$propID = mysql_real_escape_string($_GET['id']);
$query = "select propertyArea, propertyPrice, propertyType, propertyBedrooms, propertyDescription from property where propertyID = $propID";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
{
?>
<table ALIGN = "LEFT">
<font face="Arial" color="#0B3A62">
<?echo $row[0]; ?> ,
£<? echo $row[1]; ?> ,
<? echo $row[2]; ?> ,
<? echo $row[3]; ?> bedrooms,
<? echo $row[4]; ?>
<? echo $row[5];
}
}
?>
</font>
</TABLE>
</BR>
</BR>
</BR>
</BODY>
</HTML>
Re: Search result hyperlink not working
Posted: Mon Mar 31, 2008 10:41 am
by kryles
Honestly I tried doing BLOB type before and just couldn't wrap my head around it. What I ended up doing was saving the image on the server and putting the path to it in the database as a varchar.
Then in the code I'd just use an <img src="$row['PATHTOIMAGE']"> kind of setup. I would ask in a different thread though, guaranteed someone on this board can figure out BLOB
glad you got the first part up
Re: Search result hyperlink not working
Posted: Mon Mar 31, 2008 10:48 am
by khushbush
Oh dear...ok...well, no worries...I'm sure I'll get it working somehow...
Thanks again though
