Connecting Tech Pros Worldwide Forums | Help | Site Map

having problems with this sections on the script.

josh dismukes
Guest
 
Posts: n/a
#1: Jul 17 '05
//Query the Database
$query = "SELECT type FROM map WHERE map_file = " .
$_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
row = " . $_SESSION['new_row'];
$db_result = @mysql_query($query);
$db_cell_type = @mysql_fetch_array($result);

//Evaluate the Cell Type
if ($db_cell_type=='W'){
$_SESSION['new_col']=$_SESSION['old_col'];
$_SESSION['new_row']=$_SESSION['old_row'];
$_SESSION['new_map']=$_SESSION['old_map'];
$_SESSION['celltype']='W';}
elseif($db_cell_type=='T'){
$query2 = "SELECT townID FROM map WHERE map_file = " .
$_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
row = " . $_SESSION['new_row'];
$db_result2 = @mysql_query($query2);
$db_townid = mysql_fetch_array($db_result2);
$_SESSION['townID'] = $db_townid;
$_SESSION['is_town'] = 1;
$_SESSION['celltype']='T';}
else {
$_SESSION['old_col']=$_SESSION['new_col'];
$_SESSION['old_row']=$_SESSION['new_row'];
$_SESSION['old_map']=$_SESSION['new_map'];
$_SESSION['celltype']='L';}

Andy Hassall
Guest
 
Posts: n/a
#2: Jul 17 '05

re: having problems with this sections on the script.


On 30 Mar 2004 10:59:30 -0800, sk8er1796@yahoo.com (josh dismukes) wrote:
[color=blue]
>//Query the Database
> $query = "SELECT type FROM map WHERE map_file = " .
>$_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
>row = " . $_SESSION['new_row'];
> $db_result = @mysql_query($query);
> $db_cell_type = @mysql_fetch_array($result);
>
>//Evaluate the Cell Type
>if ($db_cell_type=='W'){
> $_SESSION['new_col']=$_SESSION['old_col'];
> $_SESSION['new_row']=$_SESSION['old_row'];
> $_SESSION['new_map']=$_SESSION['old_map'];
> $_SESSION['celltype']='W';}
> elseif($db_cell_type=='T'){
> $query2 = "SELECT townID FROM map WHERE map_file = " .
>$_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
>row = " . $_SESSION['new_row'];
> $db_result2 = @mysql_query($query2);
> $db_townid = mysql_fetch_array($db_result2);
> $_SESSION['townID'] = $db_townid;
> $_SESSION['is_town'] = 1;
> $_SESSION['celltype']='T';}
>else {
> $_SESSION['old_col']=$_SESSION['new_col'];
> $_SESSION['old_row']=$_SESSION['new_row'];
> $_SESSION['old_map']=$_SESSION['new_map'];
> $_SESSION['celltype']='L';}[/color]

So, do you have a question?

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Pedro Graca
Guest
 
Posts: n/a
#3: Jul 17 '05

re: having problems with this sections on the script.


josh dismukes wrote:[color=blue]
> //Query the Database
> $query = "SELECT type FROM map WHERE map_file = " .
> $_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
> row = " . $_SESSION['new_row'];
> $db_result = @mysql_query($query);[/color]

What if your query fails?
You will never know about it until later, when your script fails for
some reason that can have little relation to the failed query.
Try inserting here:

if (!$db_result) die('query failed because ' . mysql_error());


I suspect not all of $_SESSION['new_map'], $_SESSION['new_col'], and
$_SESSION['new_row'] are integers. If they are strings they need quotes
around them.
[color=blue]
> $db_cell_type = @mysql_fetch_array($result);[/color]

$db_cell_type is an array!
[color=blue]
> //Evaluate the Cell Type
> if ($db_cell_type=='W'){[/color]

When you use it in comparisons with string it will be automagically
converted to "Array" (and "Array" != "W" always)

Probably you want

if ($db_cell_type['type'] == 'W') {
[color=blue]
> $_SESSION['new_col']=$_SESSION['old_col'];
> $_SESSION['new_row']=$_SESSION['old_row'];
> $_SESSION['new_map']=$_SESSION['old_map'];
> $_SESSION['celltype']='W';}
> elseif($db_cell_type=='T'){[/color]

same mistake as before
[color=blue]
> $query2 = "SELECT townID FROM map WHERE map_file = " .
> $_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
> row = " . $_SESSION['new_row'];
> $db_result2 = @mysql_query($query2);
> $db_townid = mysql_fetch_array($db_result2);
> $_SESSION['townID'] = $db_townid;[/color]

and again
[color=blue]
> $_SESSION['is_town'] = 1;
> $_SESSION['celltype']='T';}
> else {
> $_SESSION['old_col']=$_SESSION['new_col'];
> $_SESSION['old_row']=$_SESSION['new_row'];
> $_SESSION['old_map']=$_SESSION['new_map'];
> $_SESSION['celltype']='L';}[/color]

HTH
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Closed Thread