Page 1 of 1
How to create Links in results from a MySQL Database
Posted: Tue Jul 10, 2007 8:16 am
by rach99
Hello Everyone!
I have been searching for the answer to this simple question for ages, and i am guessing it is probably a simple answer. I just can not work this out. I am teaching myself MySQL and PHP and I have a page which work fine as a search. But what i need is to have links to .php files to appear in the search results.
Basically what the website does is advertises. Each advertiser has their own page, which i need to bring up in the search results so users can click on the link and go to their particular page, I also need the search results to bring up other advertisers with similar products etc.
Any advice, tutorials or direction would be GREAT!
Thanks heaps
Rachael
Posted: Tue Jul 10, 2007 8:46 am
by boo
Are you looking for something like this
Code: Select all
<?php
$link = 'http://www.somesite.com';
$link_desc = 'Click here to visit site';
?>
<a href="<?php echo $link?>"><?php echo $link_desc ?></a>
Posted: Tue Jul 10, 2007 4:32 pm
by rach99
Hey Boo,
Thanks for the response, that is close, but what i need is maybe the headings of each result to link to their related page.
So for example:
Gary's Lawn Seed - (this to link to garys_lawn_seed.php)
gary stocks a wide range of lawn seed.....
Bills Lawn Seed - (this to link to bill_lawn_seed.php)
bills lawn seed is better then gary's......
Lawn Seed - (links to main page lawn_seed.php)
listing of lawn seed products and company's.....
So a user would click on the link (title) and it would take them to the page?
Hope i make sense, I dont even know where to start with this! lol
Posted: Tue Jul 10, 2007 5:29 pm
by Tarquinius999
Code: Select all
<?php
$link = 'http://www.somesite.com';
$link_desc = 'Click here to visit site';
?>
<a href="<?php echo $link?>"><?php echo $link_desc ?></a>
This is exactly what you want, you just need to make sure the query is able to put each out...
Code: Select all
$get_data = @mysql_query("SELECT * FROM tbl_users ORDER BY `id` ASC");
while($data=mysql_fetch_array($data))
{
$link = $data['users_link'];
$link_title = $data['users_link_title'];
echo "<a href=\"".$link."\">".$link_title."</a><br>";
}
This will produce a list based on the mysql table.
in the $data[' '] just enter your column name for each variable. and assuming you know mysql, change your query to match your table

Posted: Tue Jul 10, 2007 11:24 pm
by rach99
Where would I place the link code?
Would I create another column in my database with the .php file link?
Sorry to be a pain, but I have search for tutorials everywhere. Also if you had a moment could you note what the code you posted is doing so i can understand a bit better?
Thank you so much for your time.
Posted: Wed Jul 11, 2007 4:00 am
by Gente
rach99 wrote:Would I create another column in my database with the .php file link?
Yes you have to create a new field if you have custom page for each user. Otherwise you can write an common script and put and user_id as GET parameter
Posted: Wed Jul 11, 2007 4:11 am
by rach99
So do i just add for example
lawn_seed.php under a 'links' column?
or the full address where the website is upload like
http://www.lawnseed.com.au/lawn_advertiser1.php?
Also where is the above link code meant to be placed in my code?
Thanks
Rachael
Posted: Wed Jul 11, 2007 4:19 am
by Gente
First one.
rach99 wrote:
Also where is the above link code meant to be placed in my code?
The place where you want to see it

Posted: Wed Jul 11, 2007 4:33 am
by rach99
Code: Select all
$get_data = @mysql_query("SELECT * FROM tbl_users ORDER BY `id` ASC");
while($data=mysql_fetch_array($data))
{
$link = $data['users_link'];
$link_title = $data['users_link_title'];
echo "<a href=\"".$link."\">".$link_title."</a><br>";
}
What exactly do i replace in this code with my own info?
And where do i place this piece of code in the php code i posted above that I have? And do i need to remove any code which conflicts with this? Also do i need to add the top bit of the php that was first posted by boo with the one I just asked about in this post?
Thank you very much for you help so far, and your patience.
I am having so much trouble getting this part of it to work!

Posted: Wed Jul 11, 2007 4:54 am
by Gente
Sorry, but you should be more specific. We gave you the correct answer, so you should try something instead of asking to fix your code.
Posted: Wed Jul 11, 2007 5:29 am
by rach99
I have been working on this and going through tutorials for 2 weeks, I am trying to learn php & mysql I am not just after people to fix my code as I respect the fact that people take the time on forums to help others out for nothing.
I didnt want the answer so to speak, the code doesnt mean much at all to me that was posted, I was just after a tutorial or explaination of how to link my results to individual php pages like how google shows results and has links that follow off to different pages. Even just what i should be looking for, for example should i be reading up on array and query statements etc. (I wanted more of an understanding so to speak)
thanks to everyone who helped me out so far, I do apologise if I have given the impression I am just here for people to do my work for me.
Goodluck with the forums