Jump to content

[SOLVED] Make a "If like" statement?


djfox

Recommended Posts

Let`s say I have:

 

$res2 = mysql_query("SELECT id, evolve_next, evolve_level, name FROM pokedex WHERE id='$poke[1]'");
$pokemon = mysql_fetch_row($res2);
mysql_free_result($res2);

 

And I want PHP to check to see if , exists in $pokemon[1]. If it does, do one thing. If not, do something else.

If it does exist, how it could separate the elements that are between the commas (there may just one or more than one comma) and have an option for each of those.

 

Example:

If $pokemon[1] has "Vaporeon,Jolteon,Flareon", then be like:

Vaporeon:

Do whatever

Jolteon:

Do whatever else

Flareon:

Do something different

 

or if $pokemon[1] has "Pikachu", then do other stuff.

 

How could this be accomplished?

Link to comment
Share on other sites

Wouldn`t this mean I would have to make several $pokemon statements for it to check for each and every pokemon name that might be in the list? That would be extremely time consuming to setup, not to mention make the file huge since we`re looking at over 550 names to work with. isn`t there a tweaking to that code we could do to remove the massive workload?

Link to comment
Share on other sites

You sure? What this is addressing is the evolution stages that the pokemon would take place. Some pokemon have multiple others they can evolve into while others have just one. I can do one where it`s just the single choice, but the multiple choices I can`t figure out how to work it into a simple not-spend-a-year-coding-for-it code because there are so many of them.

Link to comment
Share on other sites

<?php
$res = mysql_query("SELECT id, species, level FROM pokemon_owned WHERE id='$p'");

$poke = mysql_fetch_row($res);

mysql_free_result($res);



$res2 = mysql_query("SELECT id, evolve_next, evolve_level, name FROM pokedex WHERE id='$poke[1]'");

$pokemon = mysql_fetch_row($res2);

mysql_free_result($res2);


$res3 = mysql_query("SELECT id, name FROM pokedex WHERE name='$pokemon[1]'");

$e = mysql_fetch_row($res3);

mysql_free_result($res3);



echo "You can evolve your pokemon into a different pokemon in which it could gain new strengths. However, this cannot be undone.";

echo " Make certain that you are absolutely sure that you want to evolve this pokemon before clicking the button below. If you";

echo " would to know what kind of pokemon yours will change into from evolving, you can view the pokedex. If your";

echo " pokemon is not a high enough level to evolve, you will see what level your pokemon needs to be before it can evolve.<p>";

if ($pokemon[1]) {

if ($poke[2] >= $pokemon[2]) {

echo "You can evolve your $pokemon[3] into $e[1]. Click the button below to evolve it.";

echo "<form action='evolve.php' method='post'>";

echo "<input type='hidden' name='pok' value='$p'><input type='hidden' name='ev' value='$e[0]'>";

echo "<p><input type='image' src='$butnext' name='submit'></form>";

}

else {

echo "Your pokemon is not a high enough level. Your pokemon must be at level $pokemon[2] before it can evolve.";

}

}

elseif (!$pokemon[1]) {

echo "This pokemon does not evolve.";

}
?>

This is how it is currently, where right now it only works if the pokemon has just one form to evolve into (it does not work for multiple forms). (Example - It will work for Pikachu because Pikachu`s only choice is Raichu. But it won`t work for Eevee because has 7 forms to choose from.)

Link to comment
Share on other sites

Wait, wait, I got it.

 

<?php
$pieces = explode(",", $pokemon[1]);
foreach ($pieces as $evo) {
$res3b = mysql_query("SELECT id, name FROM pokedex WHERE name='$evo'");
$e2 = mysql_fetch_row($res3b);
mysql_free_result($res3b);
if ($e2[1]) {
echo "<input type='radio' name='ev' value='$e2[0]'> $e2[1] <br>";
}
?>

I should`ve seen this sooner. XD This works for both single choices and multiple choices.

Link to comment
Share on other sites

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.