Forum Moderators: coopster

Message Too Old, No Replies

Displaying results as link

         

jumpstartpro

4:15 am on Jan 6, 2005 (gmt 0)

10+ Year Member



Hello fellow members. I have developed my script to search the mysql database and display the results (not all of them) for the product. As of right now it will display the reference #, location, name, and I included a small thumbnail for each listing. However the problem I have is I need for the reference # to link to a new page which will then display all of the information for that item. I have seen other sites just like what I am trying to do. When you click on there item it then takes you to a page like this:

[sitename...]

How do I make a link in the database display all of the results for that one item? I am not sure what this is even called, that is my biggest problem of not knowing what to look up. Any help would be appreciated, thank you.

dkin

6:02 am on Jan 6, 2005 (gmt 0)

10+ Year Member



what you have to do for this, I hope I can explain this correctly forgive me if I dont.

You must create a template as your link says detail.php, this page would include all the information you would like to display from your row.

In this page you must have a Select * From table where id = '$id'

It takes the id from the url.

then simply link like so

<a href="detail.php?id='.$row[id].'">'.$row[item_name].'</a>

If you need anything else just ask.

coopster

1:10 pm on Jan 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, jumpstartpro. Seems dkin has you off and running ...

jumpstartpro

5:01 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



I have no clue where to even start. Is there any tutorials that anyone knows of that I can look at as an example?

jumpstartpro

6:14 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



Ok I got it working now, thank you very much for the help.

Here is the coding I used for the display.php page. I still have to clean it up to actually match the site, but the basic working functions are here.

[code]
<?php

mysql_connect("localhost","username","password"); //(host, username, password)

mysql_select_db("database") or die("Unable to select database");

$ad = strip_tags($_GET["ad"]);

$query = "SELECT * FROM tablename WHERE ad = '$ad'";
$result = mysql_query($query) or die(mysql_error());

mysql_close();

while ($row = mysql_fetch_array($result)){

$output .= "
<tr>
<td>".$row["ad"]."</td>
<td>".$row["resort_name"]."</td>
<td>".$row["resort_location"]."</td>
<td>".$row["bed"]."</td>
<td>".$row["bath"]."</td>
<td>".$row["sales_price"]."</td>
<td>".$row["week"]."</td>
</tr>
";

}

$output .= "
</table>
</body>
</html>
";

print $output;

?>

[code]

I had found $ad = strip_tags($_GET["ad"]); in a tutorial I was reading and it worked great. In my actual database, I setup my link like this:

"http://www.sitename.com/display.php?Item1">Item1</a>

So when a search is ran on the site, my results.php script uses that link like this:

while ($row= mysql_fetch_array($result)) {
$itemname = $row["ad_number"];
<a href=$itemname

It works like a charm now. I am not the best at explaining things in PHP for I am still very new and use books to do a lot of my coding. I was able to get this to work and if anyone else is having the same problem as me, ask I and will send you the code I used.

dkin

9:14 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



WOO HOOO I was right lol, I am new to php so I like to play mod sometimes and pretend I know what Im talking about :D it worked so Im happy, good job men/women :D

jatar_k

9:54 pm on Jan 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hehe, glad you got it sorted jumpstartpro, welcome to WebmasterWorld too

>> pretend I know what Im talking about

awe c'mon dkin, I've seen you answer a bunch, you know more and more :)

by the way, mods don't know what they are talking about either, we just hide it better ;)

ergophobe

10:33 pm on Jan 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




we just hide it better

I was thinking the same thing. I'm looking forward to the day when I can hide it as well as Jatar_K and Coopster ;-)

There is a saying: "If you want to learn something, study it. If you want to master something, teach it."

dkin

12:16 am on Jan 7, 2005 (gmt 0)

10+ Year Member



I started out being a code bunny on this site, a usual post for me would be.

example

I found this code on a webmaster scripts site and its not working can somebody make all the alterations needed and and get my site working because I have no idea what php is but I would like to have a site.

they would reply with code and I would say nope dont work, anyone else

lol

I started experimenting with the codes, reading books. Going through tutorials.

Now I am writing a gaming website which I feel will be a huge success.

Thanks for all your help everyone.

p.s. Jatar, you are pretty good at hiding it.