Hi everyone,
My name is Nowy and I'm new to the forum, but was wondering if anybody could help me out with a small issue I'm facing.
I currently have the code:
[codebox]$query_games = "SELECT * FROM games ORDER BY name ASC";
$mysqlresult_games = mysql_query($query_games) or die('ERROR '.$query_games.' '.mysql_error());
while ($row_games = mysql_fetch_array($mysqlresult_games))
{
echo '<input type="checkbox" name="games[]" value="'.htmlentities(stripslashes($row_games['id'])).'"'; if (($gamescheck[0] == $row_games['id']) || ($gamescheck[1] == $row_games['id']) || ($gamescheck[2] == $row_games['id']) || ($gamescheck[3] == $row_games['id']) || ($gamescheck[4] == $row_games['id'])) { echo 'checked'; } echo '/> <img src="'.htmlentities(stripslashes($row_games['image'])).'" width="12" height="12" alt="" /> '.htmlentities(stripslashes($row_games['name'])).'<br />';
}[/codebox]
I was wondering if there was any quicker way of writing the following code as I need to go up to infinity:
[codebox]if (($gamescheck[0] == $row_games['id']) || ($gamescheck[1] == $row_games['id']) || ($gamescheck[2] == $row_games['id']) || ($gamescheck[3] == $row_games['id']) || ($gamescheck[4] == $row_games['id'])) { echo 'checked'; }[/codebox]
Thanks!
Nowy
Problem with arrays
Started by
nowy
, Aug 19 2009 07:07 PM
5 replies to this topic
#1
Posted 19 August 2009 - 07:07 PM
#2
Posted 20 August 2009 - 07:32 PM
if(in_array($row_games['id'], $gamescheck)){ echo 'checked'; }ref: http://php.net/manua...on.in-array.php
#3
Posted 21 August 2009 - 07:13 AM
[quote name='rc69' post='270845' date='Aug 21 2009, 01:32 AM']
However with the code I previously asked help with, it returns the error:
Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in xxx\functions.php on line 9
$_POST = array_map('escape', $_POST);function escape($str) { return mysql_real_escape_string($str); }
However with the code I previously asked help with, it returns the error:
Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in xxx\functions.php on line 9
#4
Posted 21 August 2009 - 09:10 AM
try this instead:
function escape($str) { $str = mysql_real_escape_string($str); return $str; }
#5
Posted 21 August 2009 - 09:18 AM
[quote name='derek.sullivan' post='270853' date='Aug 21 2009, 03:10 PM']try this instead:
$_POST = array_map('escape', $_POST);$_GET = array_map('escape', $_GET);$_COOKIE = array_map('escape', $_COOKIE);function escape($str) { $str = mysql_real_escape_string($str); return $str; }
Edited by nowy, 21 August 2009 - 09:20 AM.
#6
Posted 22 August 2009 - 01:51 PM
as long as $str is = to what you want to filter.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users