Jump to content


This topic is now archived and is closed to further replies.


[SOLVED] After calling fetchInto once, it doesn't work for the second query! help!

Recommended Posts

I've been working on this code for my site, the intention of which is to select a given number of quotes from a database at random and display them. I can select the whole database fine, but I'd kind of like to have the "quote of the day" (or 3 or so). Any thoughts on accomplishing this? I've written this much so far:

                $dsn = 'mysql://user:pass@localhost/quotes';
                $db =& DB::Connect( $dsn );
                if (PEAR::isError($db)) {die($db->getMessage());}

                $res = $db->query( "SELECT count(id) FROM quotes", array());

                $row = array(null);
                if( $res != null )

                echo "$row[0]"."<br />"; //Added for troubleshooting
                $total = $row[0];

                $nodisplay = 8;


                for($i=0; $i<$nodisplay; $i++)
                        $ids[]=rand(0, $total);
                        echo "$ids[$i]"."<br />"; //Added for troubleshooting

                $resdis = $db->query( "SELECT quote, author FROM quotes WHERE id=?", $ids);

                $eye = "<table class='quotetable' width='100%'>\n";

                if( $resdis != null )
                        while($resdis->fetchInto($morerow)) // Line 40
                        $eye.="<tr>\n<td align='right'>--";

                echo $eye;

When I run this I get this output:

Fatal error: Call to undefined method DB_Error::fetchInto() in /public_html/randtest.php on line 40[/code]

What am I missing? FetchInto worked fine the first time, can I not call it twice in the same script?

Thanks in advance for the help!

(By the by, if any one has any better ideas on how to display a "quote of the day" (or 3) chosen at random from the database, please share.)

Share this post

Link to post
Share on other sites
$morerow is (read: should be) an array containing the quote and author from the database. I didn't define it explicitly, but I tried it with:
[code]$morerow = array(null);[/code]
Right before line 40. Same error though. Does it have anything to do with the result object? I did a little snooping around pear.php.net, seems there's some functions to clear result and query (or prepare rather) objects.

Share this post

Link to post
Share on other sites
Ok. I did some tinkering. And got it working. Anyone have any ideas on randomly selecting a quote of the day that is static throughout the day?

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.