overlordofevil Posted April 18, 2008 Share Posted April 18, 2008 Hello All, I am wondering if someone could point me in the right direction or give me hints on how to do the following. I am working on a member database for a game. What I want to do is allow members to log in and purchase skills for their characters. I have a table setup with all the skills and it has the following columns: ID - numeric code Name - what the skill is called Type - what type of skill, ie. weapon, craftsman, magic, racial, etc. Prereq - what is needed to get the skill. What I want to do is pull the data and separate it into a table with column names based off of the type, so what it would show is the type as a column name and the name of the skill underneath it. Example Craftsman Weapon Magic Racial Craft skill 1 Weapon skill 1 Magic skill 1 Racial skill 3 Craft skill 2 Weapon skill 2 Magic skill 2 Racial skill 4 Where I am stuck at is I know how to pull the data and see all the skills but I don’t know how to separate it in to the columns and I haven’t found anything that helped explain it to me. I don’t want anyone to do the work for me but if you could point me to a source that would help me figure this out or explain how to do this I would appreciate it. Link to comment https://forums.phpfreaks.com/topic/101735-separating-data-in-to-specific-columns/ Share on other sites More sharing options...
Zhadus Posted April 18, 2008 Share Posted April 18, 2008 Run a query to your DB and draw the values into an array for each column e.g. weapon[] & magic[]. Then do a loop with php with outputting an HTML table and each cell include the information. Let me know if you wanted something more in depth than that. If you have an idea post the code and we can help you modify that to your needs. Link to comment https://forums.phpfreaks.com/topic/101735-separating-data-in-to-specific-columns/#findComment-520612 Share on other sites More sharing options...
overlordofevil Posted April 21, 2008 Author Share Posted April 21, 2008 thanks for the help. I have pulled the data and I am not sure if I am separating it correctly into the different arrays correctly. here's what I got. <?php include ("misc.inc"); $query = "SELECT * FROM skill_info ORDER by '$skillType'"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { extract($row); if ($skillType = "Trades and Crafts") { $trades = array("$skillName"); } elseif ($skillType = "Racial Abilities") { $racial = array("$skillName"); } elseif ($skillType = "Weapons and Armor") { $weapon = array("$skillName"); } elseif ($skillType = "Scholarly Skills") { $scholar = array("$skillName"); } elseif ($skillType = "Magic Skills") { $magic = array("$skillName"); } elseif ($skillType = "Healing Skills") { $healing = array("$skillName"); } elseif ($skillType = "Stealth Skills") { $stealth = array("$skillName"); } elseif ($skillType = "Fighting Skills") { $fighting = array("$skillName"); } } ?> so as you see I pulled the data and ordered it by the skillType. I then set up an if statement to try and separate it into the arrays based on the type. Now I am not sure how to pull the data out correctly. I have tried using a foreach statement to put it in a select menu just to test it but that doesn't give me anything other then "array{" as my output. as you can see the code below ?> <html> <body> <br align='center'><h3>NERO Skills</h3> <table border='1' cellspacing='15'> <tr><td colspan='12'><hr></td></tr> <tr><td>Trades and Crafts</td><td>Racial Abilities</td><td>Weapons and Armor</td><td>Scholarly Skills</td><td>Magic</td><td>Healing</td><td>Stealth Skills</td><td>Fighting Skills</td></tr> <?php echo "<tr>"; echo "<td> <SELECT name=trades> foreach ($trades as $key => $trades) { <OPTION trades='$trades'>$trades } </select> </td>"; echo "<td> <SELECT name=racial> foreach ($racial as $key => $racial) { <OPTION racial='$racial'>$racial } </select> </td>"; echo "<td> <SELECT name=weapon> foreach ($weapon as $key => $weapon) { <OPTION weapon='$weapon'>$weapon } </select> </td>"; echo "<td> <SELECT name=scholar> foreach ($scholar as $key => $scholar) { <OPTION scholar='$scholar'>$scholar } </select> </td>"; echo "<td> <SELECT name=magic> foreach ($magic as $key => $magic) { <OPTION magic='$magic'>$magic } </select> </td>"; echo "<td> <SELECT name=healing> foreach ($healing as $key => $healing) { <OPTION healing='$healing'>$healing } </select> </td>"; echo "<td> <SELECT name=stealth> foreach ($stealth as $key => $stealth) { <OPTION stealth='$stealth'>$stealth } </select> </td>"; echo "<td> <SELECT name=fighting> foreach ($fighting as $key => $fighting) { <OPTION fighting='$fighting'>$fighting } </select> </td>"; echo "</tr>\n"; ?> <tr><td colspan='12'><hr></td></tr> </table> </body> </html> now I know I am not setting it up into a table like I want to but I am trying to get the data to show up, somewhere along the lines i coded it wrong and i get nothing. any suggestions on where i messed up ? Link to comment https://forums.phpfreaks.com/topic/101735-separating-data-in-to-specific-columns/#findComment-523127 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.