tgavin Posted February 17, 2007 Share Posted February 17, 2007 I'm thinking of putting together a table that will contain template information. Since there's always the possibility of new things being added in the future, I don't want to create a seperate field for each item. Instead, I'll just add a new record for each item. Easy enough. Now, I also don't want to have to have a varchar field for a record that really only needs a char field. Or a text field for 50 characters of text. So I've thought about putting different field types into the table, and then only using the appropriate field type for each record. CREATE TABLE `templates` ( `temp_name` varchar(20) NOT NULL default '', `temp_char` char(1) NOT NULL default '', `temp_varchar` varchar(255) NOT NULL default '', `temp_datestamp` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`temp_name`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; So, here's where my question lies. I'm still learning arrays. Looking at the code below, is their an easier way to do what I'm seeking? $query = "SELECT temp_name,temp_char,temp_varchar FROM templates WHERE temp_name IN ('banner','link_txt')"; $sql = mysql_query($query,$conn) or die(mysql_error()); $row = array(); while($row = mysql_fetch_assoc($sql)) { $row_char[$row['temp_name']] = $row['temp_char']; $row_varchar[$row['temp_name']] = $row['temp_varchar']; } echo $row_char['banner']."<br />"; echo $row_varchar['link_txt']; Quote Link to comment Share on other sites More sharing options...
camdagr81 Posted February 19, 2007 Share Posted February 19, 2007 Sure is $query = "SELECT temp_name,temp_char,temp_varchar FROM templates WHERE temp_name IN ('banner','link_txt')"; $sql = mysql_query($query,$conn) or die(mysql_error()); while(list($temp_name, $temp_char, $temp_varchar) = mysql_fetch_row($sql)) { echo $temp_name . '<br />'; echo $temp_char . '<br />'; echo $temp_varchar . '<br />'; } Quote Link to comment Share on other sites More sharing options...
tgavin Posted February 19, 2007 Author Share Posted February 19, 2007 Cool! Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.