Jump to content

Recommended Posts

ok what i have is a switch statement through ajax that i want to make dependent to the query from the database, so like this for the switch statement

function doIt($it) {
switch ($it) {
while($row=mysql_fetch_array($res)){//i want to use a wile loop this does not work
case '$count'://i want to use a counter and increment the counter each time through
   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>";//'.$i[iD].'.
   break;
   }

}
}

and then output each switch depending on the number of results from the batabase and increment it, hopefully i am saying this correctly.

Thank you in advance

hopefully i am saying this correctly

 

Where does $res and $count come from?

 

<?php
function doIt($it) {
   switch ($it) {
   case '$count'://i want to use a counter and increment the counter each time through
      while($row=mysql_fetch_array($res)){//i want to use a wile loop this does not work
          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>";//'.$i[iD].'.
      }
      break;
   }
}
?>

Ok let me try to be more concise, what i trying to do is have a switch on the bottom that has varying lengths, such as if the database only has 1 result there will only be one there, if it has 2 then there will be 2 switches ... and so on to 6. If you need more info i can pm you some information and you can look at it in action.

Ok let me try to be more concise, what i trying to do is have a switch on the bottom that has varying lengths, such as if the database only has 1 result there will only be one there, if it has 2 then there will be 2 switches ... and so on to 6. If you need more info i can pm you some information and you can look at it in action.

From that you do not need to be using a switch at all. You need to provide a more thorough explaination of what you're. such as what is in your database? What are you wanting to do with the results etc?

From that you do not need to be using a switch at all. You need to provide a more thorough explaination of what you're. such as what is in your database? What are you wanting to do with the results etc?

 

I sent you a pm with a more helpful explanation.

Let me try to explain in more detail what i am doing.

 

I have a div at the top of my page that has a pokemon in it that was selected through the use of ajax. On the bottom i have a selection of pokemon(depending on how far you are in the game and how many you have caught) up to 6. So i am trying to get the information from the database on the pokemon that the user owns so they can be switched in and out of battle. The info in the db is... their name, hp, xp,level and stats. I am using the results in the switch to select which one is in battle. Hopefully this answers all of your questions wildteen. As you see the switch is working correctly(without the use of the db and statically assigning the information of the pokemon).

Thanks again.

This is the switch.php

<div id="pokemonwitch">
<div id="options">
<a href="ajaxswitch.php?content=1"><div class="pokemonSlot" title="header=[<font class='detailsBoxHeader'>
	<img src='images/pokemon_sprites_small/001.gif' alt='Bulbasaur' style='vertical-align:middle;' /> 
	Bulbasaurs's Details...</font>] body=[<font class='detailsBoxContent'>
	Unique #: 1 <br />
	Experience: 0<br />
	Level: 1<br />
	HP: 45/45<br />
	Status: normal<br />
	Att. 1: Horn Attack - PP Left: 25/25<br />		Att. 2: Tail Whip - PP Left: 30/30<br />		Att. 3: Stomp - PP Left: 20/20<br />		Att. 4: Fury Attack - PP Left: 20/20<br />		Attached Item: <i>none</i><br />
	Available evolve: <i>none</i>		
	</font>]"><div class="pokemonSlot"><img src="images/pokemon_sprites/001.png" alt="Bulbasaur" title="Bulbasaur"></div>
	<div class="clear"><img src="battle_files/spacer.gif" alt="sp"></div>
	<div class="pokemonSlot"><label for="battleTeam1"> <strong>Bulbasaur</strong><br><span class="smallVerdana">Level 1<br>45/45 HP</span></label></div></div></a>
<a href="ajaxswitch.php?content=2"><div class="pokemonSlot" title="header=[<font class='detailsBoxHeader'>
	<img src='images/pokemon_sprites_small/002.gif' alt='Ivysaur' style='vertical-align:middle;' /> 
	Venasaur's Details...</font>] body=[<font class='detailsBoxContent'>
	Unique #: 1 <br />
	Experience: 0<br />
	Level: 1<br />
	HP: 60/60<br />
	Status: normal<br />
	Att. 1: Horn Attack - PP Left: 25/25<br />		Att. 2: Tail Whip - PP Left: 30/30<br />		Att. 3: Stomp - PP Left: 20/20<br />		Att. 4: Fury Attack - PP Left: 20/20<br />		Attached Item: <i>none</i><br />
	Available evolve: <i>none</i>		
	</font>]"><div class="pokemonSlot"><img src="images/pokemon_sprites/002.png" alt="Venasaur" title="Venasaur"></div>
	<div class="clear"><img src="battle_files/spacer.gif" alt="sp"></div>
	<div class="pokemonSlot"><label for="battleTeam1"> <strong>Venasaur</strong><br><span class="smallVerdana">Level 1<br>60/60 HP</span></label></div></div></a>
<a href="ajaxswitch.php?content=3"><div class="pokemonSlot" title="header=[<font class='detailsBoxHeader'>
	<img src='images/pokemon_sprites_small/003.gif' alt='Ivysaur' style='vertical-align:middle;' /> 
	Ivysaurs's Details...</font>] body=[<font class='detailsBoxContent'>
	Unique #: 1 <br />
	Experience: 0<br />
	Level: 1<br />
	HP: 80/80<br />
	Status: normal<br />
	Att. 1: Horn Attack - PP Left: 25/25<br />		Att. 2: Tail Whip - PP Left: 30/30<br />		Att. 3: Stomp - PP Left: 20/20<br />		Att. 4: Fury Attack - PP Left: 20/20<br />		Attached Item: <i>none</i><br />
	Available evolve: <i>none</i>		
	</font>]"><div class="pokemonSlot"><img src="images/pokemon_sprites/003.png" alt="Ivysaur" title="Ivysaur"></div>
	<div class="clear"><img src="battle_files/spacer.gif" alt="sp"></div>
	<div class="pokemonSlot"><label for="battleTeam1"> <strong>Venasaur</strong><br><span class="smallVerdana">Level 1<br>80/80 HP</span></label></div></div></a>
</div>
</div>

so this is as if they had only 3 pokemon. And this is the content.php.

function doIt($it) {
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;
}
}

thanks alot for your help. Let me know if you need additional information. The hp xp level name and id# which is the 00X will be pulled from the db which is already setup.

I want to try to give just a little more info so i am not posting for no reason. What i am doing is pulling UP TO 6 records from a mysql database then outputting the information so that when it is clicked it will be moved to the top without refreshing the whole page, i posted the switch i am using to do it with ajax. I hope it has been explained thuroughly enough if not tell me what else you need and i will be happy to respond.

 

Thank you everyone.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.