Markbad311
09-28-2006, 03:48 PM
I am having a slight difficultly with my SELECT statement.
first here is what my DB looks like
ROW ID INFO
1 4 stuff
2 6 stuff
3 1 stuff
I have a script like this that counts how many rows are there and picks a random number between the first row and the total rows. Problem is I don't know how to reference the data by row in the next Select Statement. Here is the PHP
<?
function Banners()
{
$table_name = "inbound_links";
$sqlCount = "SELECT id FROM $table_name";
$resCount = mysql_query($sqlCount) or die(mysql_error());
$x = mysql_num_rows($resCount);
$row = rand(1,$x);
/*RIGHT HERE I NEED THE ROW REFERENCE NOT ID LIKE IT IS CURRENTLY*/
$sqlBanner = "SELECT * FROM $table_name WHERE `id` = '$row'";
$resBanner = mysql_query($sqlBanner) or die(mysql_error());
while($rowBanner = mysql_fetch_array($resBanner))
{
$img = ($rowBanner['sub_banner']);
$name = ($rowBanner['site_name']);
$url = ($rowBanner['site_url']);
$desc = ($rowBanner['site_description']);
$banner = "<br/><a href=\"$url\"><img src=\"$img\" alt=\"$name\" border=\"0\"></a><br/>$desc<br/><br/>";
}
echo "$banner";
}
?>
first here is what my DB looks like
ROW ID INFO
1 4 stuff
2 6 stuff
3 1 stuff
I have a script like this that counts how many rows are there and picks a random number between the first row and the total rows. Problem is I don't know how to reference the data by row in the next Select Statement. Here is the PHP
<?
function Banners()
{
$table_name = "inbound_links";
$sqlCount = "SELECT id FROM $table_name";
$resCount = mysql_query($sqlCount) or die(mysql_error());
$x = mysql_num_rows($resCount);
$row = rand(1,$x);
/*RIGHT HERE I NEED THE ROW REFERENCE NOT ID LIKE IT IS CURRENTLY*/
$sqlBanner = "SELECT * FROM $table_name WHERE `id` = '$row'";
$resBanner = mysql_query($sqlBanner) or die(mysql_error());
while($rowBanner = mysql_fetch_array($resBanner))
{
$img = ($rowBanner['sub_banner']);
$name = ($rowBanner['site_name']);
$url = ($rowBanner['site_url']);
$desc = ($rowBanner['site_description']);
$banner = "<br/><a href=\"$url\"><img src=\"$img\" alt=\"$name\" border=\"0\"></a><br/>$desc<br/><br/>";
}
echo "$banner";
}
?>