View Single Post
Old 07-22-2003, 09:46 AM   #4 (permalink)
mpedrummer2
Insane
 
I sorta got it, but I have another question, this time with examples.

Code:
 function get_set($table,$column) {
	$sql = "SHOW COLUMNS FROM $table LIKE '$column'";
		if (!($ret = mysql_query($sql))){
			die("Error: Could not show columns");
		}
		$line = mysql_fetch_assoc($ret);
		$set = $line['Type'];
		$set = substr($set,5,strlen($set)-7); // Remove"set(" at start and ");" at end
		return preg_split("/','/",$set); // Split into and array
		}
That's the function I'm using to create the array that contains the information I need.

http://test.komta.com/test%20form.php

You can see it in action there. All the select items were created this way, using the following call...

Code:
// Create colorType select field
$colorset = $db->get_set(iris, colorType);
echo 'select name="colorType" size="1"\n';
foreach ($colorset as $row) {
	echo "option value =\"$row\">$row</option>\n";
	}
echo '</select><br>';
// End colorType /select
// I had to get rid of the < before select and option, TFP was trying to render it
I have the function in an included class ($db), that's why the function is called that way.

So, here's my question...if you look at the selects, you'll notice that 3 of them have an ' in front of the first value. I don't know where it's coming from, and I'd really like to get rid of it...

I don't think it's the function, because it works with the other ones with no problem.

Shit. I know what it is...the ones that aren't working are ENUM, not SET, so when I remove the first 5 characters of $set, I'm not removing enough...ok, nevermind. I'm posting this anyway because it was a pain in the ass to type.

MPEDrummer
__________________
My sig can beat up your honor student.

Last edited by mpedrummer2; 07-22-2003 at 09:58 AM..
mpedrummer2 is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54