For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > March 2004 > having problems with this sections on the script.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author having problems with this sections on the script.
josh dismukes

2004-03-30, 2:31 pm

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

2004-03-30, 5:35 pm

On 30 Mar 2004 10:59:30 -0800, sk8er1796@yahoo.com (josh dismukes) wrote:

>//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';}


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

2004-03-30, 6:33 pm

josh dismukes wrote:
> //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);


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.

> $db_cell_type = @mysql_fetch_array($result);


$db_cell_type is an array!

> //Evaluate the Cell Type
> if ($db_cell_type=='W'){


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') {

> $_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'){


same mistake as before

> $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;


and again

> $_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';}


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 :
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com