Array works locally but not on server???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
loco_ola
Forum Newbie
Posts: 15
Joined: Wed Oct 15, 2003 7:10 am

Array works locally but not on server???

Post by loco_ola »

When it loads on the net server it just makes a blank page, it works locally.... if i do the same but not in an array it works.... :wink:
Anyone got any ideas?

Many thanks

Code: Select all

<?php require_once('Connections/conwildtangent.php');

error_reporting  (E_ERROR | E_WARNING | E_PARSE); 

mysql_select_db($database_conwildtangent, $conwildtangent);
$rsservicetext = "SELECT tblprojects.projectid, tblprojects.projectname, tblprojects.projecticon, tblprojects.projecttext, tblservicedata.servicedataid, tblprojectassociations.projectassociationid, tblprojectassociations.projectid, tblprojectassociations.servicetypeid FROM tblprojects INNER JOIN (tblprojectassociations INNER JOIN tblservicedata ON tblprojectassociations.servicetypeid=tblservicedata.servicedataid) ON tblprojectassociations.projectid=tblprojects.projectid";


$query = mysql_query($rsservicetext); 

if (mysql_num_rows($query) > 0) { 
   while ($row_rsservicetext = mysql_fetch_array($query, MYSQL_ASSOC)) { 
      $cells[] = '<a href="projects.php?projectid='.$row_rsservicetext['projectid'].'"><img src="images/'.$row_rsservicetext['projecticon'].'" alt="'.$row_rsservicetext['projecticon'].'" name="icon_3dvis" border="0" id="icon_3dvis"><strong><br><h6></strong></a><a href="projects.php?projectid='. $row_rsservicetext['projectid'].'"><strong>'.$row_rsservicetext['projectname'].'</strong></a></h6>'; 
   } 
} 

// $cells is the array holding the cell contents 

$numcells = count($cells); 
$perline = 3; 
$lines = $numcells / $perline; 
if (!is_int($lines)) { $lines = intval($lines) + 1;} 
$n = 0; 

for ($i = 1; $i <= $lines; $i++) { 
   $table .= '<tr>'; 
   for ($i2 = 1; $i2 <= $perline; $i2++) { 
      $table .= '<td>'.$cells[$n].'</td>'; 
      $n++; 
   } 
   $table .= '</tr>'; 
} 

$table = '<table>' .$table. '</table>'; 
 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>TESTING</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php echo $table; ?>
</body>
</html>
<?php mysql_free_result($query); ?>
Thanks again guys you help is invaluable!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if it is a completely blank page (even when opening the browser's sourceview) then it's most likely a parse error.
But maybe a bit more debug-output can help

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<?php require_once('Connections/conwildtangent.php');
error_reporting(E_ALL);
ini_set('display_errors', TRUE);

mysql_select_db($database_conwildtangent, $conwildtangent) or die('connecting databse failed: '.mysql_error());

$rsservicetext = "SELECT tblprojects.projectid, tblprojects.projectname, tblprojects.projecticon, tblprojects.projecttext, tblservicedata.servicedataid, tblprojectassociations.projectassociationid, tblprojectassociations.projectid, tblprojectassociations.servicetypeid FROM tblprojects INNER JOIN (tblprojectassociations INNER JOIN tblservicedata ON tblprojectassociations.servicetypeid=tblservicedata.servicedataid) ON tblprojectassociations.projectid=tblprojects.projectid";
$query = mysql_query($rsservicetext) or die('query failed: '.mysql_error());

if (mysql_num_rows($query) > 0) {
   while ($row_rsservicetext = mysql_fetch_array($query, MYSQL_ASSOC)) {
      $cells[] = '<a href="projects.php?projectid='.$row_rsservicetext['projectid'].'"><img src="images/'.$row_rsservicetext['projecticon'].'" alt="'.$row_rsservicetext['projecticon'].'" name="icon_3dvis" border="0" id="icon_3dvis"><strong><br><h6></strong></a><a href="projects.php?projectid='. $row_rsservicetext['projectid'].'"><strong>'.$row_rsservicetext['projectname'].'</strong></a></h6>';
   }
}

// $cells is the array holding the cell contents

$numcells = count($cells);
$perline = 3;
echo '<tr><th colspan="', $perline, '">', $numcells, ' cells</th></tr>';
$lines = $numcells / $perline;
if (!is_int($lines)) { $lines = intval($lines) + 1;}
$n = 0;

for ($i = 1; $i <= $lines; $i++) {
   $table .= '<tr>';
   for ($i2 = 1; $i2 <= $perline; $i2++) {
      $table .= '<td>'.$cells[$n].'</td>';
      $n++;
   }
   $table .= '</tr>';
}

$table = '<table>' .$table. '</table>';

?>

<head>
<title>TESTING</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php echo $table; ?>
</body>
</html>
exposing the mysql_error and simply die() might not be the best idea, but this is only about debugging, isn't it? ;)
loco_ola
Forum Newbie
Posts: 15
Joined: Wed Oct 15, 2003 7:10 am

Post by loco_ola »

Thanks volka,

If i run it on the internet server it returns the following:

query failed: You have an error in your SQL syntax near '(tblprojectassociations INNER JOIN tblservicedata ON tblprojectassociations.serv' at line 1

if i run it locally it returns

7 cells
Notice: Undefined variable: table in C:\web\wildtangentdesign\arrayerrors.php on line 28

Notice: Undefined offset: 7 in C:\web\wildtangentdesign\arrayerrors.php on line 30

Notice: Undefined offset: 8 in C:\web\wildtangentdesign\arrayerrors.php on line 30

Any ideas on how to fix this?
Thanks again for the help.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

You have to fix your SQL query because it's broken somewhere..

Code: Select all

query failed: You have an error in your SQL syntax near '(tblprojectassociations INNER JOIN tblservicedata ON tblprojectassociations.serv' at line 1
... once that's done you'll probaly find that the 'undefined variable' and 'undefined offset' errors vanish.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

which version of mysql do you use at home(?) at which on the server?
In case of doubt try

Code: Select all

<pre><?php
// <-- fill in valid values
$dbHost = '***';
$dbUser = '***';
$dbPass = '***';
// ->
$connection = mysql_connect($dbHost, $dbUser, $dbPass);
print_r(mysql_get_server_info($connection));
?></pre>
loco_ola
Forum Newbie
Posts: 15
Joined: Wed Oct 15, 2003 7:10 am

Had a poke around..

Post by loco_ola »

Changed the SQL slightly and removed some repeat names....

now i get the following errors

Code: Select all

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /files/home/wildtangent/arraytest.php on line 14

Notice: Undefined variable: cells in /files/home/wildtangent/arraytest.php on line 22

Notice: Undefined variable: table in /files/home/wildtangent/arraytest.php on line 37
and the code is as such:

Code: Select all

<?php
<?php
error_reporting(E_ALL); 
ini_set('display_errors', TRUE); 

require_once('Connections/conwildtangent.php'); 

mysql_select_db($database_conwildtangent, $conwildtangent); 

$query_rsservicetext = "SELECT tblprojects.projectid, tblprojects.projectname, tblprojects.projecticon, tblprojects.projecttext, tblservicedata.servicedataid, tblprojectassociations.projectassociationid, tblprojectassociations.servicetypeid FROM tblprojects INNER JOIN (tblprojectassociations INNER JOIN tblservicedata ON tblprojectassociations.servicetypeid=tblservicedata.servicedataid) ON tblprojectassociations.projectid=tblprojects.projectid"; 

$rsservicetext = mysql_query($query_rsservicetext); 

if (mysql_num_rows($rsservicetext) > 0) { 
   while ($row_rsservicetext = mysql_fetch_array($rsservicetext, MYSQL_ASSOC)) { 
      $cells[] = '<a href="projects.php?projectid='.$row_query['projectid'].'"><img src="images/'.$row_rsservicetext['projecticon'].'" alt="'.$row_rsservicetext['projecticon'].'" name="icon_3dvis" border="0" id="icon_3dvis"><strong><br><h6></strong></a><a href="projects.php?projectid='. $row_rsservicetext['projectid'].'"><strong>'.$row_rsservicetext['projectname'].'</strong></a></h6>'; 
   } 
} 

// $cells is the array holding the cell contents 

$numcells = count($cells); 
$perline = 3; 
$lines = $numcells / $perline; 
if (!is_int($lines)) { $lines = intval($lines) + 1;} 
$n = 0; 

for ($i = 1; $i <= $lines; $i++) { 
   $table .= '<tr>'; 
   for ($i2 = 1; $i2 <= $perline; $i2++) { 
      $table .= '<td>'.$cells[$n].'</td>'; 
      $n++; 
   } 
   $table .= '</tr>'; 
} 

$table = '<table>' .$table. '</table>'; 
 


?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<?php 
echo $table; 
?> 


</body>
</html>

?>
loco_ola
Forum Newbie
Posts: 15
Joined: Wed Oct 15, 2003 7:10 am

Post by loco_ola »

Internet Server - 3.23.56 1
Local Server - 4.0.14-nt 1

so is there any way i can make this sql work in both versions?

Code: Select all

SELECT tblprojects.projectid, tblprojects.projectname, tblprojects.projecticon, tblprojects.projecttext, tblservicedata.servicedataid, tblprojectassociations.projectassociationid, tblprojectassociations.projectid, tblprojectassociations.servicetypeid FROM tblprojects INNER JOIN (tblprojectassociations INNER JOIN tblservicedata ON tblprojectassociations.servicetypeid=tblservicedata.servicedataid) ON tblprojectassociations.projectid=tblprojects.projectid GROUP BY tblprojects.projectid
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://www.mysql.com/doc/en/News-4.0.5.html
D.3.13 Changes in release 4.0.5 (13 Nov 2002)

Functionality added or changed:
[...]
Allow braces in joins in all positions. Formerly, things like SELECT * FROM (t2 LEFT JOIN t3 USING (a)), t1 worked, but not SELECT * FROM t1, (t2 LEFT JOIN t3 USING (a)). Note that braces are simply removed, they do not change the way the join is executed.
loco_ola
Forum Newbie
Posts: 15
Joined: Wed Oct 15, 2003 7:10 am

Post by loco_ola »

still couldnt make it work :( im about ready to throw this computer out . thanks for still trying volka
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

hm, my knowledge of sql is really limited. It's sufficient to create my own querries but I often fail to see why someone tries to do this or that. Could you please explain
FROM tblprojects INNER JOIN (tblprojectassociations INNER JOIN tblservicedata ON tblprojectassociations.servicetypeid=tblservicedata.servicedataid) ON tblprojectassociations.projectid=tblprojects.projectid
to me? esp. the part with the brackets and why you've used them there?
If the above is true and bracktes are simply removed you have something like "ON conditionA ON conditionB which is not a valid join-condition (afaik). Is it supposed to be some kind of subquery?

you can download older versions of mysql, so you can test with the same configuration locally. http://downloads.mysql.com/archives.php?p=mysql-3.23
loco_ola
Forum Newbie
Posts: 15
Joined: Wed Oct 15, 2003 7:10 am

Post by loco_ola »

Basically it selects all producs and their information from the product table along with which services they are listed under (they can be more than one type of serve) and the corresponding service information.

It doesnt make a difference if i remove the quotes and try to rearrange it.

The SQL is right, but it just doesnt pull the data off. but the database does exist and the data is filled in. It also pulls off all the data individually.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

As a last resort you could do...

Code: Select all

if(substr(mysql_get_server_info(), 0, 1) == '4'){
    $sql = '...one that works in version 4 here...';
}else{
    $sql = '...one that works in version 3 here...';
}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

EXPLAIN SELECT tblprojects.projectid, tblprojects.projectname, tblprojects.projecticon, tblprojects.projecttext, tblservicedata.servicedataid, tblprojectassociations.projectassociationid, tblprojectassociations.projectid, tblprojectassociations.servicetypeid FROM tblprojects INNER JOIN (tblprojectassociations INNER JOIN tblservicedata ON tblprojectassociations.servicetypeid=tblservicedata.servicedataid) ON tblprojectassociations.projectid=tblprojects.projectid GROUP BY tblprojects.projectid
returns
Impossible WHERE noticed after reading const tables
which usually is a sign for an invalid/nonsense query.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /files/home/wildtangent/arraytest.php on line 14

Notice: Undefined variable: cells in /files/home/wildtangent/arraytest.php on line 22

Notice: Undefined variable: table in /files/home/wildtangent/arraytest.php on line 37
this means the previous query failed, but without

Code: Select all

$rsservicetext = mysql_query($query_rsservicetext) or die(mysql_error());
you won't notice until it's too late ;)
loco_ola
Forum Newbie
Posts: 15
Joined: Wed Oct 15, 2003 7:10 am

Post by loco_ola »

any suggestions on how to do this another way without the two inner joins, becauase i seem to be able to make it work with one.

Thanks again
Post Reply