smithygotlost Posted November 13, 2007 Share Posted November 13, 2007 What is wrong with this script <?php function get_map($row_min,$row_max,$column_min,$column_max){ $query = mysql_query("SELECT row,columns,movable FROM rooms WHERE room_id = 'some room id' SORT BY row ASC") or die(mysql_error()); while($row = mysql_fetch_array($query)){ $columns = explode("|",$row['columns']); $movable = explode("|",$row['movable']); if(count($columns) != count($movable)){ die("I'm sorry, this room is under construction at the moment."); } while($i=0;$i<count($columns);$i++){ $cell[$row['row']][$columns[$i]] = $movable[$i]; } } mysql_free_result($query);//this will help to clear off the memory so we don't bog the server down $map = "<table border=0 cellpadding=0 cellspacing=0>"; //format of array: $cell[ROW][COLUMN] = TRUE/FALSE; foreach($cell as $index=>$row){ if($index >= $row_min && $index <= $row_max){ $map .= "\t<tr id='row_$index'>\n"; foreach($row as $column=>$movable){ if($column >= $column_min && $column <= $column_max){ if($movable){$src = 'orange_square.gif';} else {$src = 'blank_square.gif';} $map .= "\t\t<td id='column_$column'><img src='$src' alt='$src'></td>\n"; } } $map .= "\t</tr>\n"; } } $map .="</table>"; return $map; } $holder = get_map(21,25,13,17);//this can be ONE map from row 21-25 and column 13-18 $holder2 = get_map(1,5,56,60);//this can be another map from row 1-5 and column 56-60 $partial_map = get_map(1,5,1,6);//rows 1-5, columns 1-6 echo $partial_map; ?> i get this error Parse error: syntax error, unexpected ';' in /hsphere/local/home/bogblob/rpg.theblackmagic.co.uk/dc.php on line 15 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 13, 2007 Share Posted November 13, 2007 because you using a while loop like a for loop? Quote Link to comment Share on other sites More sharing options...
toplay Posted November 13, 2007 Share Posted November 13, 2007 This syntax: while($i=0;$i<count($columns);$i++){ is really used in a "for" loop. http://us2.php.net/manual/en/control-structures.for.php Edit: cooldude832 beat me to it. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 13, 2007 Share Posted November 13, 2007 This line: <?php while($i=0;$i<count($columns);$i++) ?> shouldn't be a "while" statement, it should be a "for loop": <?php for ($i=0;$i<count($columns);$i++) ?> Ken (two folks beat me to it...) Quote Link to comment Share on other sites More sharing options...
revraz Posted November 13, 2007 Share Posted November 13, 2007 You need to escape the single quote here too if(count($columns) != count($movable)){ die("I\'m sorry, this room is under construction at the moment."); Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 13, 2007 Share Posted November 13, 2007 I should report both you to an admin for double posting, oh wait you are one Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 13, 2007 Share Posted November 13, 2007 No need to escape the single quote since it's within a double quoted string. Ken Quote Link to comment Share on other sites More sharing options...
smithygotlost Posted November 13, 2007 Author Share Posted November 13, 2007 Im now getting You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'columns,movable FROM room WHERE room_id = '1' SORT BY row ASC' at line 1 can anyone help ? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 13, 2007 Share Posted November 13, 2007 You are using MySQL reserved names for field names, so you have to enclose them in backticks ( ` ): <?php $query = mysql_query("SELECT `row`,`columns`,movable FROM rooms WHERE room_id = 'some room id' SORT BY row ASC") or die(mysql_error()); ?> Ken Quote Link to comment Share on other sites More sharing options...
smithygotlost Posted November 13, 2007 Author Share Posted November 13, 2007 wow i must sound retarded now You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SORT BY row ASC' at line 1 last error i hope Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 13, 2007 Share Posted November 13, 2007 It's not "sort" it's "order". Ken Quote Link to comment Share on other sites More sharing options...
smithygotlost Posted November 13, 2007 Author Share Posted November 13, 2007 omg this is ment to have been writen by a top php person and now i get Warning: Invalid argument supplied for foreach() in /hsphere/local/home/bogblob/rpg.theblackmagic.co.uk/dc.php on line 36 Warning: Invalid argument supplied for foreach() in /hsphere/local/home/bogblob/rpg.theblackmagic.co.uk/dc.php on line 36 Warning: Invalid argument supplied for foreach() in /hsphere/local/home/bogblob/rpg.theblackmagic.co.uk/dc.php on line 36 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.