HighDots Forums  

Semi OT: Random Link Script

Search Engine Optimization Discussion about SEO/Search Engine Optimization (alt.internet.search-engines)


Discuss Semi OT: Random Link Script in the Search Engine Optimization forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
SEO Dave
 
Posts: n/a

Default Semi OT: Random Link Script - 06-08-2005 , 01:41 PM







Working on a random link script that I'm stuck on. Not strictly SEO,
but if I can get the answer here I won't have to go to a PHP type
newsgroup where they talk another language :-)

Plan is to use a MySQL database to randomly select a link from to add
to the menu of a page.

Database is setup, have got it to work within a *.php page, but when I
try to convert to a tpl template it fails and not sure why.

The script code is-

define ('HOSTNAME', 'localhost');
define ('USERNAME', '****');
define ('PASSWORD', ****');
define ('DATABASE_NAME', '****');

$db = mysql_connect(HOSTNAME, USERNAME, PASSWORD) or die ('I cannot
connect to MySQL.');

mysql_select_db(DATABASE_NAME);

$query = "SELECT Site,URL FROM links ORDER by rand() LIMIT 1";

$result = mysql_query($query);

while ($row = mysql_fetch_array($result)) {
$linked1 = "<a href=\"" , ($row['URL']) , "\"><img class=\"menu\"
src=\"dot.jpg\" alt=\"" , nl2br($row['Site']) , "\">" ,
nl2br($row['Site']) , "</a>";
}

mysql_free_result($result);
mysql_close();

Then include %%linked1%% within the menu of the tpl file associated
with the php file above. When I try this the link doesn't show.

The code I've got working is as above, but this-

$linked1 = "<a href=\"" , ($row['URL']) , "\"><img class=\"menu\"
src=\"dot.jpg\" alt=\"" , nl2br($row['Site']) , "\">" ,
nl2br($row['Site']) , "</a>";

Is replaced with this-

echo "<a href=\"" , ($row['URL']) , "\"><img class=\"menu\"
src=\"dot.jpg\" alt=\"" , nl2br($row['Site']) , "\">" ,
nl2br($row['Site']) , "</a>";

Which means all I've changed is echo to $linked1 =

This (the echo one) results in the random link showing at the bottom
of the footer php file (as expected since the code is at the bottom of
the file). So the concept works.

Since I'm using a tpl based template it needs to be converted from
using echo to the above type format and it seems I've made an error in
the conversion.

What I'm after is this format-

<a href="URL"><img class="menu" src="dot.jpg" alt="Site">Site</a>

Where URL is the url from the database and Site is the links anchor
text from the database. Been stuck on it for over an hour!

Thanks for any help.

David
--
Free Search Engine Optimization Tutorial
http://www.seo-gold.com/tutorial/

Reply With Quote
  #2  
Old   
zootreeves@gmail.com
 
Posts: n/a

Default Re: Semi OT: Random Link Script - 06-09-2005 , 08:06 AM






What does the script output when you use $linked1 = ?

Try this:

$linked1[] = "<a href='$row['URL']'><img class='menu' src='dot.jpg'
alt='$row['Site']'>$row['Site']</a>";

If you want the links as an array use:

$linked1[] =

Or if you want them to be join as one big string use:

$linked1 .=

Hope that was some help


Reply With Quote
  #3  
Old   
Gateway Farm
 
Posts: n/a

Default Re: Semi OT: Random Link Script - 06-09-2005 , 08:53 AM




"SEO Dave" <seodave (AT) search-engine-optimization-services (DOT) co.uk> wrote in
message news:nfbea1d6gvpd0kvt3jmlllfk2lonuri4on (AT) 4ax (DOT) com...
Quote:
Working on a random link script
The code I've got working is as above, but this-

$linked1 = "<a href=\"" , ($row['URL']) , "\"><img class=\"menu\"
src=\"dot.jpg\" alt=\"" , nl2br($row['Site']) , "\">" ,
nl2br($row['Site']) , "</a>";

Is replaced with this-

echo "<a href=\"" , ($row['URL']) , "\"><img class=\"menu\"
src=\"dot.jpg\" alt=\"" , nl2br($row['Site']) , "\">" ,
nl2br($row['Site']) , "</a>";

Which means all I've changed is echo to $linked1 =

It is early in the morning and I am still drinking my first coffee, so take
this with a grain of salt...

You are going to have to print or echo that variable for it to show, which
you are not doing in the first example above. In your menu can you not
simply:

<? echo $linked1; ?>

Of course, you will need to require_once() the script that defines $linked1
on your template page...

John Merrell
Gateway Farm Alpacas
http://www.gateway-alpacas.com
Alpaca, a natural elegance...




Reply With Quote
  #4  
Old   
SEO Dave
 
Posts: n/a

Default Re: Semi OT: Random Link Script - 06-09-2005 , 08:52 PM



On 9 Jun 2005 05:06:18 -0700, "zootreeves (AT) gmail (DOT) com"
<zootreeves (AT) gmail (DOT) com> wrote:

Quote:
What does the script output when you use $linked1 = ?
No, it causes the PHP file it's part of not to work at all. so if I
have it as part of the footer, the footers missing.

Quote:
Try this:

$linked1[] = "<a href='$row['URL']'><img class='menu' src='dot.jpg'
alt='$row['Site']'>$row['Site']</a>";

If you want the links as an array use:

$linked1[] =

Or if you want them to be join as one big string use:

$linked1 .=

Hope that was some help
Neither worked, but thanks for trying, got a solution from alt.php

This is what I ended up with-

$linked1 = '<a href="'. $row['URL'] .'"><img class="menu"
src="dot.jpg" alt="'. ($row['Site']) .'">'. ($row['Site']) . '</a>';

David
--
Free Search Engine Optimization Tutorial
http://www.seo-gold.com/tutorial/


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.