Jump to content

Whats wrong here


smithygotlost

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
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.