Nak Posted February 12, 2011 Share Posted February 12, 2011 Alright, I've never been too hot with PHP. Especially with math. But I'm in the process of learning it myself from a book I bought at a local store. I've hit a stump and I'm not really sure what to do. Basically what I am trying to do is : DB Table : Quality - INT - 5 From 1 through 5 will have different qualities of items for a game. What I am trying to do is pull each int from 1 to 5 out, define the int with a var, and assign that var to color an item name. If this is possible, or I sound like an idiot, please let me know. =\ Link to comment https://forums.phpfreaks.com/topic/227421-int-variable-assign-help/ Share on other sites More sharing options...
requinix Posted February 12, 2011 Share Posted February 12, 2011 pull each int from 1 to 5 out, define the int with a var, and assign that var to color an item name What? You mean use the number to pick one (of five) colors? MySQL? How much have you learned about it yet? Used mysql_query() yet? Link to comment https://forums.phpfreaks.com/topic/227421-int-variable-assign-help/#findComment-1173123 Share on other sites More sharing options...
Veteah Posted February 21, 2011 Share Posted February 21, 2011 I think see what you're trying to do. Say you had an item's id passed through $_POST $colours = array(1 => 'EE0000', 2 => 'E3CF57', 3 => '6E8B3D', 4 => '00688B', 5 => '8968CD'); $item_id = preg_replace("/[^\d\]/", "", $_POST['id']); // remove everything that's not a number $sql = "SELECT `item_name`, `item_colour` FROM item_table WHERE item_id = '". $item_id ."'"; $run = mysql_query($sql); $row = mysql_fetch_assoc($run); $selected_colour = $row['item_colour']; $selected_name = $row['item_name']; /* Say the field item_colour is a number from 1 to 5 depending on what colour you want it to be. You would then use the field to act as the means of selecting the array key from $colours */ echo '<p style="color: #'. $colours[$selected_colour] .';">'. $selected_name .'</p>'; So if the query came back as 3 for item_colour the above would be the same as saying: <p style="color: #'. $colours[3] .';">'. $selected_name .'</p> Which would make the page's html be: <p style="color: #6E8B3D;">ITEM NAME</p> Hope that helps. Link to comment https://forums.phpfreaks.com/topic/227421-int-variable-assign-help/#findComment-1177718 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.