I've been having some trouble, though. I can't get the query to write to an array. I'm not sure where I'm going wrong with my code. Perhaps one of you can figure it out:
$db = new PDO( 'mysql:host=localhost;dbname=fluue_pokemon', "fluue_***removed***", "***removed***" );
//set limit based on form drop down box
$limit = $_POST['pokemonlimit'];
//set pokemon type base on form
$t = $_POST['t1'];
switch ($t) //determines which group to query
{
case 0:
$type = '%';
break;
case 1:
$type = 'grass';
break;
case 2:
$type = 'fire';
break;
case 3:
$type = 'ground';
break;
default:
echo "Error!";
}
$i=1; //set base value for looping - we want it to loop only the set number of times as in $limit!
do
{
$i++;
$stmt = $db->prepare( "
SELECT *
FROM pokemon
WHERE type1 LIKE :type1
" );
var_dump($stmt->execute( array(
"type1" => $type
)));
$rows = array($stmt);
if( var_dump($rows = $stmt->fetchAll()) )
{
print_r( $rows[ rand() ] );
}
else
{
die( "Bugger.\n" );
}
}
while($i<=$limit);
Any help to fixing this would be greatly appreciated. Thanks!


Sign In
Create Account

Back to top









