php - Displaying Random Row from SQL Database -
I am working for days now and I am at a dead end I am positive after talking to GoDaddy support That I have the correct hostname, username / password when I run the script but it still can not get die ()
Finally, I am attempting to draw a question from a database. I have compiled this website, but I could not find anything, it seems to answer my question. help please.
& lt ;? Php $ hostname = 'localhost'; $ User name = 'username'; $ Password = 'password'; $ Dbname = 'qod'; $ Usertable = 'question'; $ Userfield = 'question'; Mysql_connect ($ hostname, $ username, $ password) or die ("& lt; html> Lit script language = 'javascript' & gt; WARNING ('Unable to reach day's question! Please try again later . '), History .go (-1) & lt; / script & gt; & lt; / html & gt; "); Mysql_select_db ($ dbname); # If the record is present then $ query = 'SELECT $ .userfield FROM $. Sure Rand () Border 1); $ Result = mysql_query ($ query); If ($ result) {while ($ row = mysql_fetch_array ($ result)) {$ name = $ row [$ yourfield]; Echo "name:". $ Name;}}? & Gt;
You are using points for your SELECT variable, where none needed.
SELECT $ .userfield FROM $ .usertable
, then call them from:
$ usertable = 'question'; $ Userfield = 'question'; Remove them from your SELECT and use the appropriate techniques like:
and
or die ('could not connect:'. Mysql_error ());
The dollar sign in the [$ yourfield]
for the name of your column; Also remove it.
You should use quotes: Ie: ['yourfield']
- yourfield
due to the name of the column in your table that you want Takedown Notes:
mysql _ *
Task Removal Notification:
This extension forms PHP 5.5.0 , And is not recommended to write new codes because it will be removed in the future, instead, extensions or extensions should be used instead. See also for more help when choosing a MySQL API.
These functions allow you to access MySQL database servers. More information about MySQL can be found at ».
Documentation for MySQL can be found at ».
Use, or.
Comments
Post a Comment