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/