Jump to content

Error in code


PHPNEWTOIT

Recommended Posts

Hi

 

This query was written by a query coder who does not know php but is excellent with queries but I cant seem to get it to run. I just get a blank page.

 

<?php 
$hostname = "localhost"; 
$database = "sextoys"; 
$username = "sextoys"; 
$password = "sextoys"; 
mysql_connect($hostname, $username, $password) or die(mysql_error()); 
mysql_select_db($database) or die(mysql_error()); 
$query="SELECT t1.title AS lev1, t1.sectionID AS id1, 
        t2.title as lev2, t2.sectionID AS id2, 
        t3.title as lev3, t3.sectionID AS id3, 
        t4.title as lev4, t4.sectionID AS id4 
FROM jss_sections AS t1  
LEFT JOIN jss_sections AS t2 ON t2.parent = t1.sectionID  
LEFT JOIN jss_sections AS t3 ON t3.parent = t2.sectionID  
LEFT JOIN jss_sections AS t4 ON t4.parent = t3.sectionID
where t1.title='Main Section'";
$result=mysql_query($query);
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}
while ($row = mysql_fetch_assoc($result)) {
if ( $row['id1'] != $id1 ) 
    { 
        echo $row['lev1'] . "<br/>\n"; 
        $id2 = -1; $id3 = -1; $id4 = -1; 
        $id1 = $row['id1']; 
    } 
    if ( isset($row['id2'] && $row['id2'] != $id2 ) 
    { 
        echo $row['lev1'] . " >> " . $row['lev2'] . "<br/>\n"; 
        $id3 = -1; $id4 = -1; 
        $id2 = $row['id2']; 
    } 
    if ( isset($row['id3'] && $row['id3'] != $id3 ) 
    { 
        echo $row['lev1'] . " >> " . $row['lev2'] . " >> " . $row['lev3'] . "<br/>\n"; 
        $id4 = -1; 
        $id3 = $row['id3']; 
    } 
    if ( isset($row['id4'] && $row['id4'] != $id4 ) 
    { 
        echo $row['lev1'] . " >> " . $row['lev2'] . " >> " . $row['lev3'] . " >> " . $row['lev4'] . "<br/>\n"; 
        $id4 = $row['id4']; 
    } 
} 
mysql_close(); 
mysql_free_result($result);
?>

 

I have tested the query on its own and it seems to work ok as well as the php code upto the second if statement as as soon as i include that nothing shows anymore.

 

Can anyone see what I have done wrong.

 

Thanks in advance

 

Roy

Link to comment
Share on other sites

Usually a blank page means you have a fatal error in your script and displaying errors is turned off.

 

You can put this at the top of your script while developing to help out with debugging and it would have given you the same information jl5501 gave.  Plus any other errors on the page.

ini_set('display_errors',1);
error_reporting(E_ALL);

Link to comment
Share on other sites

Hi

 

I have tried everything tonight to try and fix this all I know at the moment is that the issue is in the 2nd part of the script the 2nd if statement.

 

$query="SELECT t1.title AS lev1, t1.sectionID AS id1,   
        t2.title as lev2, t2.sectionID AS id2,   
        t3.title as lev3, t3.sectionID AS id3,   
        t4.title as lev4, t4.sectionID AS id4   
FROM jss_sections AS t1    
LEFT JOIN jss_sections AS t2 ON t2.parent = t1.sectionID    
LEFT JOIN jss_sections AS t3 ON t3.parent = t2.sectionID    
LEFT JOIN jss_sections AS t4 ON t4.parent = t3.sectionID  
where t1.title='Main Section'"; 
$id1 = -1;  
$result = mysql_query($query) or die(mysql_error()); 
while($row = mysql_fetch_array($result)){ 
if ( $row['id1'] != $id1 )   
{   
echo $row['lev1'] . "<br/>\n";     
$id2 = -1; $id3 = -1; $id4 = -1; $id1 = $row['id1']; 
} 
if (isset($row['id2'] && $row['id2'] != $id2 ))  
    {  
        echo $row['lev1'] . " >> " . $row['lev2'] . "<br/>\n";  
        $id3 = -1; $id4 = -1;  
        $id2 = $row['id2'];  
    }  
}   

mysql_close(); 
?>  

 

If I stop the code at the 2nd if I get one result through which is correct for that level. The 2nd part of the script should bring out a further 80+ result but I just get a blank screen.

 

I have tried DEBUG and get no errors, I have PHP error reporting on and it shows nothing wrong but all I get is this blank page.

 

Any help please.

 

Roy

Link to comment
Share on other sites

if you put this

 
ini_set('display_errors',1);
error_reporting(E_ALL);

at the top of your script it should've give you something along these lines

PHP Parse error:  syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in test.php on line 19

Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in test.php on line 19

which is this line

if (isset($row['id2'] && $row['id2'] != $id2 ))

which should be

if (isset($row['id2']) && $row['id2'] != $id2 )

 

 

 

Link to comment
Share on other sites

Hi

 

Thanks for the code as soon as I changed the part you gave me it went through.

 

However I have that code at the top of the page as you said and used the original code and it came up with no errors again just a blank page.

 

Can you check if its in the correct place and anything else I can check to ensure it works as it will save me ages.

 

Thanks again for you help

 

Roy

 

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$hostname = "localhost"; 
$database = "sextoys"; 
$username = "sextoys"; 
$password = "sextoys"; 
mysql_connect($hostname, $username, $password) or die(mysql_error()); 
mysql_select_db($database) or die(mysql_error()); 
$query="SELECT t1.title AS lev1, t1.sectionID AS id1,  
        t2.title as lev2, t2.sectionID AS id2,  
        t3.title as lev3, t3.sectionID AS id3,  
        t4.title as lev4, t4.sectionID AS id4  
FROM jss_sections AS t1   
LEFT JOIN jss_sections AS t2 ON t2.parent = t1.sectionID   
LEFT JOIN jss_sections AS t3 ON t3.parent = t2.sectionID   
LEFT JOIN jss_sections AS t4 ON t4.parent = t3.sectionID 
where t1.title='Main Section'";
$id1 = -1; 
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
if ( $row['id1'] != $id1 )  
{  
echo $row['lev1'] . "<br/>\n";    
$id2 = -1; $id3 = -1; $id4 = -1; $id1 = $row['id1'];
}
if (isset($row['id2'] && $row['id2'] != $id2 ))
    { 
        echo $row['lev1'] . " >> " . $row['lev2'] . "<br/>\n"; 
        $id3 = -1; $id4 = -1; 
        $id2 = $row['id2']; 
    } 
}  

mysql_close();
?> 

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.