1
$sql23 = "SELECT * FROM map1pokemon ORDER BY RAND() LIMIT 1;";
$result23 = mysql_query($sql23) or die(mysql_error());
$battle_get23 = mysql_fetch_array($result23);


$sql2 = "SELECT * FROM pokemon WHERE name='".$battle_get23['pokemon']."'";
$result2 = mysql_query($sql2) or die(mysql_error());
$battle_get2 = mysql_fetch_array($result2);


$filler = "SELECT * FROM pokemon WHERE name='Charmander'";
$filler2 = mysql_query($filler) or die(mysql_error());
$filler3 = mysql_fetch_array($filler2);


$pokemon1 = array_fill(1,10,"".$filler3."");
$pokemon2 = array_fill(1,2,"".$battle_get2."");
$pokemon3 = array_merge($pokemon1, $pokemon2);
shuffle($pokemon3);
$pokemon4 = array_shift($pokemon3);


$pic2= mysql_real_escape_string($pokemon4['pic']);
$pic = strip_tags($pic2);


echo "<center>";
echo '<img src="pokemon/'.$pic.'" border=0><p></p>' ;

The queries at the top grab the information about each pokemon, I then want to use the array_fill and array_merge to make it harder for one of the results to appear the, but right now it doesn't show the result of the pokemon after the mixing of the pokemon, I believe that I'm doing the mixing of the pokemon wrong, but have no idea why?

Does anyone see what I'm doing wrong here?

Nick
  • 213
  • 1
  • 9
  • 2
    [Please, don't use `mysql_*` functions](http://stackoverflow.com/q/12859942/1190388) in new code. They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the red box? Learn about prepared statements instead, and use [tag:PDO] or [tag:MySQLi]. – hjpotter92 Apr 07 '13 at 08:09
  • I know this, people say it in everyone one of my questions XD I will eventually switch, but for now I'm using this because it's what I know :/ – Nick Apr 07 '13 at 08:12
  • 1
    Stop using it now before you make a mess of things. PDO only takes [a half hour to learn](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/). Every line of code you're writing here will be broken in future versions of PHP, so spend the small amount of time now to brush up on PDO and save yourself the trouble later. If you use [SQL placeholders](http://bobby-tables.com/php) you will eliminate dangerous [SQL injection bugs](http://bobby-tables.com/) for free. – tadman Apr 07 '13 at 08:13
  • Also why are you escaping `$pic` HTML for MySQL and not escaping `$battle_get23` which is actually used in MySQL? Seems like a little [cargo cult programming](http://en.wikipedia.org/wiki/Cargo_cult_programming) is going on here. – tadman Apr 07 '13 at 08:16
  • Alright, well I'm not worried about all of that right now guys, just need the problem at hand solved :/ – Nick Apr 07 '13 at 08:17

1 Answers1

2

this line seems to be useless :

$pic2= mysql_real_escape_string($pokemon4['pic']);

Then, it is logical you do not display what you want as you do not store what you want. Let's review your code :

 $filler = "SELECT * FROM pokemon WHERE name='Charmander'";
 $filler2 = mysql_query($filler) or die(mysql_error());
 $filler3 = mysql_fetch_array($filler2);

$filter3 is clearly an array which contains all of your table columns.

$pokemon1 = array_fill(1,10,"".$filler3."");

What? you concatenate an array with a string? Don't use this concate trick it will not bring you good results. $pokemon1 = array_fill(1,10,$filler3); is ok. A little greedy but ok.

One thing you can do is using random generator, it will be easier to use, less greedy and quicker.

$rand = rand(12);
if($rand <=10){
     $result = $filler3;
}else{
     $result = $battle;
}
echo $result['name'];
artragis
  • 3,677
  • 1
  • 18
  • 30
  • What do you mean by "greedy" also where is that rand(12) coming from? – Nick Apr 07 '13 at 08:20
  • Well thanks, I still used my way just found another solution, thanks non the less :) I'm sure your way works to so i'll accept it. – Nick Apr 07 '13 at 08:31
  • rand is the function that generate a positive integer randomly. It is a built in function. "greedy" stands for "your solution takes a lot of place in memory and a lot of time to execute". – artragis Apr 07 '13 at 08:46
  • I see, well that doesn't really do what I need completely, I only have partially what I needed done in the code I provided. – Nick Apr 07 '13 at 15:21