0

Hi, I have a bit of a strange problem where I am unable to "echo" results from a database -

I will show you the code then explaine what im trying to do

<?php
include_once "connect_to_mysql.php";
 
$sql = mysql_query("SELECT * FROM table ORDER BY RAND(), LIMIT 1");

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

	$add = $row["add"];
	$link = $row["link"];
	$title = $row["title"];
	
	echo "
		<b>$add</b>
		<a href='$add'$link</a>						
		";
	
	}	
	
?>

db has the following fields id, add, link, title

The script to connect to the database works fine, as if i change the host, it gives me an error.

But im not getting any images from the database

What im trying to do is, randomly select any field and link the add field using the link field, so if a user clicks the add shown, it will take them to the website address in the link field.

Im also not sure how to add the title, so when a user hovers over the add shown, it will show a title tag ???

Can someone provide any helpful guidance to help me learn more coding skills.

Thanks to those who reply,
Lloyd

4
Contributors
4
Replies
13
Views
7 Years
Discussion Span
Last Post by vaultdweller123
0

Hm, what kind of query is that?

mysql_query("SELECT * FROM table ORDER BY RAND(), LIMIT 1");

I guess...

<?php
include_once "connect_to_mysql.php";
 
$sql = mysql_query("SELECT * FROM table");
 
while($row = mysql_fetch_assoc($sql))
{ 
 
	$add = $row['add'];
	$link = $row['link'];
	$title = $row['title'];
 
	echo '
		<b>'.$add.'</b>
		<a href="'.$add.$link.'" title="'.$title.'"></a>';
 
}	
 
?>
0

hi thanks for your post reply,

The query searches the db randomly selects one add and displays it

What you provided gave an error !!

I tried
<a href='$link'target='_blank'>$title</a> which worked, but im not getting the add to show as its in a java script format as shown below
*****************************************
<script type="text/javascript">
var uri = 'http://impgb.tradedoubler.com/imp?type(img)g(22222222)a(2222222)' + new String (Math.random()).substring (2, 11);
document.write('<a href="http://clkuk.tradedoubler.com/click?p=18710&a=1710341&g=22222222" target="_BLANK"><img src="'+uri+'" border=0></a>');
</script>
*********************************************************
im trying to rotate my adds from tradedoubler but im not sure if its possible to display java script correctly from a mysql db ??

Thanks for your help

lloyd

0

you had syntax error on your query

SELECT * FROM table ORDER BY RAND(), LIMIT 1

erase the comma next to RAND(), it should look something like this

SELECT * FROM table ORDER BY RAND() LIMIT 1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.