Forum Moderators: coopster

Message Too Old, No Replies

Php switch statement populated from Database

Making this into an array i think

         

littlehelp

6:25 pm on Jul 11, 2009 (gmt 0)

10+ Year Member



Ok i was looking through the internet and such and i saw that the way to populate a switch through a database is to change the switch to a array, i am unsure of how to go about this.
i have a switch that looks like this:

switch ($it) {
case "1":
return "<div style=\"width: 100px; height: 84px; text-align: center; float: left;\"><img src=\"images/pokemon_sprites/001.png\" width=\"100\" height=\"100\" /></div><div style=\"overflow: hidden; width: 100px; float: left; padding-top: 32px; line-height: normal;\"><strong>Bulbasaur</strong><br><span class=\"smallVerdana\">Level 1<br /><div class=\"clear\"><img src=\"battle_files/spacer.gif\" alt=\"sp\"></div>
<div style=\"width: 100px; text-align: left;\">
<div class=\"hpBar\" style=\"width: 100%;\"><img src=\"battle_files/spacer.gif\" alt=\"sp\" style=\"height: 12px;\"></div>45/45 Hit Points<br /><div class=\"clear\"><img src=\"battle_files/spacer.gif\" alt=\"sp\"></div></div>";
break;
case "2":
return "<p><div style=\"width: 100px; height: 84px; text-align: center; float: left;\"><img src=\"images/pokemon_sprites/002.png\" width=\"100\" height=\"100\" /></div><div style=\"overflow: hidden; width: 100px; float: left; padding-top: 32px; line-height: normal;\"><strong>Ivysaur</strong><br><span class=\"smallVerdana\">Level 1<br /><div class=\"clear\"><img src=\"battle_files/spacer.gif\" alt=\"sp\"></div>
<div style=\"width: 100px; text-align: left;\">
<div class=\"hpBar\" style=\"width: 100%;\"><img src=\"battle_files/spacer.gif\" alt=\"sp\" style=\"height: 12px;\"></div>60/60 Hit Points<br /><div class=\"clear\"><img src=\"battle_files/spacer.gif\" alt=\"sp\"></div></div>";
break;
case "3":
return "<p><div style=\"width: 100px; height: 84px; text-align: center; float: left;\"><img src=\"images/pokemon_sprites/003.png\" width=\"100\" height=\"100\" /></div><div style=\"overflow: hidden; width: 100px; float: left; padding-top: 32px; line-height: normal;\"><strong>Venasaur</strong><br><span class=\"smallVerdana\">Level 1<br /><div class=\"clear\"><img src=\"battle_files/spacer.gif\" alt=\"sp\"></div>
<div style=\"width: 100px; text-align: left;\">
<div class=\"hpBar\" style=\"width: 100%;\"><img src=\"battle_files/spacer.gif\" alt=\"sp\" style=\"height: 12px;\"></div>80/80 Hit Points<br /><div class=\"clear\"><img src=\"battle_files/spacer.gif\" alt=\"sp\"></div></div>";
break;
}

how many Pokemon the user has and the picture, name, level and hp will be pulled from the database, so the cases will max at 6 but could be any number between 1-6.

So any help with this would be amazing.
Thanks in advance

eelixduppy

9:45 pm on Jul 11, 2009 (gmt 0)



I am unsure what you are actually trying to do, can you please elaborate on this. From my understanding it looks like you want to grab up to 6 rows from a database table and display them appropriately.

Also, it seems from what I can put together that a switch statement is not exactly what you are looking for here. Perhaps once we find out what you are trying to do we can come up with the best possible solution for this.

littlehelp

10:04 pm on Jul 11, 2009 (gmt 0)

10+ Year Member



ok there is up to 6 selections on the bottom(they are pokemon) when selected it will go to the top(to battle), i am doing this through ajax with a switch and it is working.What is not working is being able to tell the switch when there is only 2 pokemon or when there is a full grouping(6) and i need to pull the info from the database, i cant use a while loop to pull the information, i can do it through php but not with the switch. That is my problem.