Question : fast random row script issue

Hi everyone,

I have found a decent script online for producing fast random rows from large mysql tables. My skill in php is non existent and I found another tutorial online for displaying the random row. I have got it to work but I am getting errors reported to do with a variable $i. the errors are as follows:

Notice: Undefined variable: i in /Volumes/My Book/DataBases/Cura Romana Project DB/Cura Romana Project/Folders/Website (dreamweaver) Files/Random quote test/randomtest1.php on line 16

Notice: Undefined variable: i in /Volumes/My Book/DataBases/Cura Romana Project DB/Cura Romana Project/Folders/Website (dreamweaver) Files/Random quote test/randomtest1.php on line 17

to display the info on the page I am using <? echo $FrontQuote; ?> and <? echo $FrontAuthor; ?>

If I remove the $i from the code the error disappears but the FrontQuote and FrontAuthor do not display and only display the FrontID primary key field

I realize the mistake is mine but I do not know enough to be able to fix it.

Thank you so much for your help as always
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
<?php
// Mysql Database Config
$db_host = 'localhost';
$db_db   = 'Quotes';
$db_user = 'root';
$db_pass = 'root';

// Mysql Connection
$db_link = mysql_connect($db_host, $db_user, $db_pass)
	or die('MySQL Connection Error:'.mysql_error());
mysql_select_db($db_db)
	or die('MySQL Error: Cannot select table');
$sql = "SELECT * FROM FrontQuote WHERE FrontID = ROUND(".lcg_value()." * (SELECT COUNT(*) FROM FrontQuote)) LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$FrontQuote=mysql_result($result,$i,"FrontQuote");
$FrontAuthor=mysql_result($result,$i,"FrontAuthor");
?>

Answer : fast random row script issue

Here you go
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
<?php
// Mysql Database Config
$db_host = 'localhost';
$db_db   = 'Quotes';
$db_user = 'root';
$db_pass = 'root';

// Mysql Connection
$db_link = mysql_connect($db_host, $db_user, $db_pass)
        or die('MySQL Connection Error:'.mysql_error());
mysql_select_db($db_db)
        or die('MySQL Error: Cannot select table');
$sql = "SELECT * FROM FrontQuote WHERE FrontID = ROUND(".lcg_value()." * (SELECT COUNT(*) FROM FrontQuote)) LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$FrontQuote = $row['FrontQuote'];
$FrontAuthor = $row['FrontAuthor'];
?>
Random Solutions  
 
programming4us programming4us