Page 1 of 1

Getting ENUM fields from MySQL Database *NEW Problem*

Posted: Wed Jan 27, 2010 1:26 pm
by D.M.N.
A quick look on Google doesn't come up with anything 'complete', so posting here. I'm doing an SQL database. In brief, I've got a table in the database called 'Unit_01'.

Within the database is a particular field under the 'ENUM' data type which can be set to either 'Pass' or 'Fail'. I've got several records, some set to 'Pass' and some set to 'Fail'.

How do I get this into a PHP script so the output would be what is shown in the MySQL database?

I did try following http://www.barattalo.it/2010/01/19/php- ... sql-field/ but got extremely confused as to where the 'Pass' and 'Fail' bits would go.

I presume this is actually possible. Any help, is appreciated. :)

Re: Getting ENUM fields from MySQL Database

Posted: Wed Jan 27, 2010 2:04 pm
by requinix
Are you trying to show what's in the table, or what values are allowed for that ENUM field?
Because the link you gave is about doing the latter.

For the former, any PHP+MySQL tutorial will tell you how.

Re: Getting ENUM fields from MySQL Database

Posted: Wed Jan 27, 2010 2:35 pm
by D.M.N.
tasairis wrote:Are you trying to show what's in the table, or what values are allowed for that ENUM field?
Because the link you gave is about doing the latter.

For the former, any PHP+MySQL tutorial will tell you how.
Thanks for the reply. I want to show what value in the table, whether it is 'Pass' or 'Fail' in my case.

Do you have links to PHP+MySQL tutorials which do say about ENUM fields? I've tried looking but to no avail. :(

Re: Getting ENUM fields from MySQL Database

Posted: Wed Jan 27, 2010 2:36 pm
by pickle
Like all other data pulled into PHP from MySQL, all values are strings. Just a regular query that asks for that column should get you "Pass" or "Fail" as a string.

Re: Getting ENUM fields from MySQL Database

Posted: Wed Jan 27, 2010 2:39 pm
by D.M.N.
pickle wrote:Like all other data pulled into PHP from MySQL, all values are strings. Just a regular query that asks for that column should get you "Pass" or "Fail" as a string.
Thanks for the speedy reply... I'll try that. Cheers. :)

Re: Getting ENUM fields from MySQL Database

Posted: Wed Jan 27, 2010 2:55 pm
by D.M.N.
And it worked! Thank you. :)

Re: Getting ENUM fields from MySQL Database

Posted: Thu Jan 28, 2010 8:17 am
by D.M.N.
Hi,

I've got a secondary problem on the database which is slightly related to the above.

As noted, I've got several tables in my database. In summary, this is how they are:

User_data
Fields - Student_ID, Username, Password among other things

Unit_01 to Unit _05 then Unit_10
Fields - Student_ID, P1... P5, M1... M3, D1 (varies slightly from unit to unit, but Student_ID is always there)

How do I link the Student_ID in the Unit_01 to Unit_10 tables with the 'user_data' table, as Student ID #2 in 'unit_data' corresponds with the Student ID #2's "Unit_01.... Unit_10" stuff.

At the moment, when I log in with Student ID #2, using info from the user_data table, I get Student ID #1's "Unit_01... Unit_10" data, which obviously shouldn't be happening, as they aren't for the same person.

Thanks to anyone who can help - hopefully it makes sense. :)

Re: Getting ENUM fields from MySQL Database *NEW Problem*

Posted: Thu Jan 28, 2010 10:17 am
by AbraCadaver
No telling without the code.

Re: Getting ENUM fields from MySQL Database *NEW Problem*

Posted: Thu Jan 28, 2010 1:48 pm
by D.M.N.
AbraCadaver wrote:No telling without the code.
Which part of the code? The code I made after the users above told me how to do it? :?

Code: Select all

<?php
 
$result = mysql_query("SELECT * FROM Unit_01") or die(mysql_error());  
// Retrieve data from "Unit_01" table
 
$row = mysql_fetch_array($result);
// store data from "Unit_01" table into $row
 
echo $row['P2'];
// Print contents, either Pass or Fail
 
?>

Re: Getting ENUM fields from MySQL Database *NEW Problem*

Posted: Fri Jan 29, 2010 4:07 am
by D.M.N.
Anyone? :S

Re: Getting ENUM fields from MySQL Database *NEW Problem*

Posted: Mon Feb 01, 2010 9:41 am
by pickle
If you've got a new question - best to post it separately.