crf121359 Posted March 22, 2012 Share Posted March 22, 2012 Hello, I am trying to display the texts that is stored in mysql in a textarea on a random basis. here is my code: <?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"]; } but when I run the above code I get this error and also the textarea doesn't show anything and its blank: 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 Quote Link to comment Share on other sites More sharing options...
smerny Posted March 22, 2012 Share Posted March 22, 2012 remove this line: $data = mysql_fetch_assoc($result1); change this line: while($row = mysql_fetch_array($result1)){ Quote Link to comment Share on other sites More sharing options...
crf121359 Posted March 22, 2012 Author Share Posted March 22, 2012 OMG smerny, You are my God... you don't know how long I've been trying to resolve this issue!! Thank you sooooo much. works like a charm now. Now, just to pick your brains again, can you tell me how I can show the texts randomly? for example I have 10 columns in my mysql table with different texts in each of them. how can i randomly show the contents of each columns in the same textarea? Quote Link to comment Share on other sites More sharing options...
smerny Posted March 22, 2012 Share Posted March 22, 2012 try appending "ORDER BY RAND()" to your query... most efficient method if you are selecting multiple fields and lots of data, but it should be fine for what you are doing Quote Link to comment Share on other sites More sharing options...
smerny Posted March 22, 2012 Share Posted March 22, 2012 i meant to say *not the most efficient... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.