Getting ENUM fields from MySQL Database *NEW Problem*

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
D.M.N.
Forum Newbie
Posts: 11
Joined: Wed Jan 27, 2010 12:43 pm

Getting ENUM fields from MySQL Database *NEW Problem*

Post 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. :)
Last edited by D.M.N. on Thu Jan 28, 2010 1:51 pm, edited 2 times in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Getting ENUM fields from MySQL Database

Post 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.
D.M.N.
Forum Newbie
Posts: 11
Joined: Wed Jan 27, 2010 12:43 pm

Re: Getting ENUM fields from MySQL Database

Post 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. :(
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Getting ENUM fields from MySQL Database

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
D.M.N.
Forum Newbie
Posts: 11
Joined: Wed Jan 27, 2010 12:43 pm

Re: Getting ENUM fields from MySQL Database

Post 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. :)
D.M.N.
Forum Newbie
Posts: 11
Joined: Wed Jan 27, 2010 12:43 pm

Re: Getting ENUM fields from MySQL Database

Post by D.M.N. »

And it worked! Thank you. :)
D.M.N.
Forum Newbie
Posts: 11
Joined: Wed Jan 27, 2010 12:43 pm

Re: Getting ENUM fields from MySQL Database

Post 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. :)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post by AbraCadaver »

No telling without the code.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
D.M.N.
Forum Newbie
Posts: 11
Joined: Wed Jan 27, 2010 12:43 pm

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

Post 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
 
?>
D.M.N.
Forum Newbie
Posts: 11
Joined: Wed Jan 27, 2010 12:43 pm

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

Post by D.M.N. »

Anyone? :S
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post by pickle »

If you've got a new question - best to post it separately.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply