View Single Post
Old 10-30-2005, 07:56 PM   · #8
SquireQuack
NamePros Member
 
SquireQuack's Avatar
 
Trader Rating: (5)
Join Date: Aug 2005
Posts: 125
NP$: 512.00 (Donate)
SquireQuack is on a distinguished road
Quote:
PHP Code:
//get a random quote... using arrays.

//Be sure to connect to the db.
$query1 = "SELECT * FROM quotes";
$result1 = mysql_query($query1);
while (
$row1 = mysql_fetch_array($result1))
{
    
$id1 = $row1['id'];
    
$array1[count($array1) + 1] = $id1;
    
    
shuffle($array1);
}
shuffle($array1);

//ACCESS THE RANDOM NUMBER IS BY $array1[0]
//Now we have the id of the random quote.

$random = $array1[0];

$q1 = "SELECT * FROM quotes WHERE id='$random' LIMIT 1";
$r1 = mysql_query($q1);

while (
$row1 = mysql_fetch_array($r1))
{
    
$content = $row1['content'];
    
$author = stripslashes($row1['author']);
}

//Then just echo $content and $author (the person who said it) when you need it.
?>


It may not be efficient but it works



it's returning this error aoubt how in
PHP Code:
while ($row1 = mysql_fetch_array($r1))

$r1 is not a valid MySQL resource for mysql_fetch_array

I'm sure I did everything right (including connecting to the database). To prove it: when I replace
PHP Code:
$q1 = "SELECT * FROM quotes WHERE id='$random' LIMIT 1";

with
PHP Code:
$q1 = "SELECT * FROM quotes WHERE 1 LIMIT 1";

It returns with my first quote.

Just wondering...how do I fix the error? Thanks!


Please register or log-in into NamePros to hide ads
__________________
upload² |AIMForum.com - Ready, AIM, Chat!|Google Talk Forum - Where the world talks about Google!
Forum Elves - Quality Forum Posting At Affordable Prices! -|Order A Package|PaidPosts.com Help Boost Your Forum|BannerManage.com Sell direct advertisements on your website effortlessly!
SquireQuack is offline   Reply With Quote
Site Sponsors
Affordable Shared, Reseller and Master Reseller Hosting Skilled Graphics Affordable Shared, Reseller and Master Reseller Hosting
Advertise your business at NamePros
All times are GMT -7. The time now is 08:31 PM.


Powered by: vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.