freelance84
03-29-2010, 07:03 PM
Hi,
I've been learning PHP/MySQL over the past few weeks from a book.
I've now created sql database and some php scripts that can retrieve, add and delete content from all the different tables within them.
One of the tables has one field named 'answers', this a VARCHAR(200) and contains strings of text/numbers.
What I want to be able to do is query the entire table into one array, then use the shuffle() function to randomly select one answer.
Here's my code so far (appears after a radio button form):
if (isset($_POST['q1']))
{$selected = $_POST['q1'];
$query = "SELECT * FROM m$selected";
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
$test=mysql_fetch_field($result);
print_r ($test);
}
Surely print_r($test); should display an array of all the entries from the table?
This is what i get from the FETCH:
"Warning: mysql_fetch_field(): supplied argument is not a valid MySQL result resource"
I've been learning PHP/MySQL over the past few weeks from a book.
I've now created sql database and some php scripts that can retrieve, add and delete content from all the different tables within them.
One of the tables has one field named 'answers', this a VARCHAR(200) and contains strings of text/numbers.
What I want to be able to do is query the entire table into one array, then use the shuffle() function to randomly select one answer.
Here's my code so far (appears after a radio button form):
if (isset($_POST['q1']))
{$selected = $_POST['q1'];
$query = "SELECT * FROM m$selected";
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
$test=mysql_fetch_field($result);
print_r ($test);
}
Surely print_r($test); should display an array of all the entries from the table?
This is what i get from the FETCH:
"Warning: mysql_fetch_field(): supplied argument is not a valid MySQL result resource"