display texts from Mysql in textarea randomly? please Help

Hello, I have been trying to show some texts that is stored in mysql in a textarea on a random basis with no luck.

Here is my code:

[php]<?php
mysql_connect(“localhost”, “myusername”, “mypass”) or die(“Connection Failed”);
mysql_select_db(“mydatabase”)or die(“Connection Failed”);

$query1 = (“SELECT name FROM advertising”);
$result1 = @mysql_query ($query1) or die (mysql_error());
$data = mysql_fetch_assoc($result1);

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

$name = $row["name"];

}

?>

<?php echo "$namet"; ?>
[/php]

and when I run the code I get this error and also nothing shows in the textarea:

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/path…/public_html/display.php on line 9

could someone please help me?

Thanks

its $query1 :slight_smile:

There’s nothing random about that script. it does exactly what you’re telling it to do. What i used to do is do a seperate query to get the last id, then use a rand() to select a random id (using the last id as the max), then do another query using a WHERE clause for that id that’s picked.

Also, this part: <?php echo "$namet"; ?> is wrong, it should be: <?php echo $name; ?>

WRONG:
[php]
$result1 = @mysql_query ($query1) or die (mysql_error());
$data = mysql_fetch_assoc($result1);

while($row = mysql_fetch_array($query)){
[/php]

RIGHT:
[php]
$result1 = mysql_query ($query1) or die (mysql_error());

while($row = mysql_fetch_assoc($result1)){
[/php]

But, you should read a MySQL tutorial to understand it… Here is a good link for you to start at…
http://www.w3schools.com/php/php_mysql_intro.asp
Click NEXT-CHAPTER until you know enough… It is a great basic start that should help you a lot…

its not technically wrong, he’s not using the information from that variable.

What’s off is the error suppression. its off, then on, off then on :slight_smile: this has to be one heck of a confused script when it runs lol :slight_smile:

LOL, yep! That’s why I gave him something to read up on it…

Sponsor our Newsletter | Privacy Policy | Terms of Service