problem running function

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
Sosi
Forum Newbie
Posts: 9
Joined: Thu May 07, 2009 5:13 pm

problem running function

Post by Sosi »

hello!

I want to run this script, but it returns no errors... I wonder if it has to do with the arguments.
Can someone please help me?

You can check the table I'm using in here. Sorry, I couldn't use the attachment option bellow because of file incompatibilities.

Thanks a lot for your help!

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
 
include 'config.php';
 
$i=1;
function apanharfilhos($a,$i){
    $i++;
    $a = 1;
    $pais1 = mysql_query("SELECT init_id FROM `interage` WHERE number='".$i."'",$conn) or die('<hr />MySQL Error: '.mysql_error().'<hr />');
    while($pais = mysql_fetch_array($pais1)){
        $array1 = array();
        array_push($array1,$pais);}
        print_r($array1);
    foreach($array1 as $key){
        $filhos3 = mysql_query("SELECT final_id FROM `interage` WHERE init_id='".$key."'",$conn) or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');;
        $filhos3 = array ();
while($filhos2 = mysql_fetch_assoc($filhos3)){
        array_push($filhos3,$filhos2);}
        $final2 = mysql_query("SELECT final_id FROM `interage` WHERE init_id='".$filhos3[0]."' AND number=1",$conn) or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');;
        $final3 = array ();
        while($final = mysql_fetch_assoc($final2)){
            array_push($final3,$final);}
        mysql_query("INSERT INTO TABLE `interage`(init_id,final_id,number) VALUES('".$key."','".$final3[0]."','".$i."')",$conn)or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');;
        }
        }
?>
Last edited by Benjamin on Thu May 07, 2009 9:18 pm, edited 1 time in total.
Reason: Changed code type from text to php.
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

Re: problem running function

Post by ldougherty »

Hello,

The information you provided doesn't really allow a whole lot to troubleshoot with. So you are not getting any errors on screen but the script is not executing properly?

Do you have access to the raw server logs? If you do look in the server error log to see exactly what is happening when you run the script.
Sosi
Forum Newbie
Posts: 9
Joined: Thu May 07, 2009 5:13 pm

Re: problem running function

Post by Sosi »

ldougherty wrote:Hello,

The information you provided doesn't really allow a whole lot to troubleshoot with. So you are not getting any errors on screen but the script is not executing properly?
Hi! Well, I'm using Wamp5 and executing the script through localhost on mozilla firefox. Is there any other way to check the errors? Because when I run the script this way, I allways get the errors in mozilla (if there are any). And no, it isn't inserting any lines in the table as it should :(
ldougherty wrote:Do you have access to the raw server logs? If you do look in the server error log to see exactly what is happening when you run the script.


Is there any way of checking that on phpmyadmin?
Sorry, I'm new in this and I dont really know how to do this stuff yet.

Thanks a lot for your effort!
Sosi
Forum Newbie
Posts: 9
Joined: Thu May 07, 2009 5:13 pm

Re: problem running function

Post by Sosi »

McInfo wrote:The apanharfilhos() function is defined but it is never called.
Wow, I missed that D: Thanks

Well, I've corrected the script for that, but it still doesnt insert lines into my table :?

Most recent code:

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
 
include 'config.php';
 
$i=0;
$a=1;
function apanharfilhos($a,$i){
    global $i;
    global $a;
    $pais1 = mysql_query("SELECT init_id FROM `interage` WHERE number='".$i."'") or die('<hr />MySQL Error: '.mysql_error().'<hr />');
    while($pais = mysql_fetch_array($pais1)){
        $array1 = array();
        array_push($array1,$pais);
        }
    global $array1; 
    foreach($array1 as $key){
        $filhos3 = mysql_query("SELECT final_id FROM `interage` WHERE init_id='".$key."'") or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');;
        $filhos3 = array ();
while($filhos2 = mysql_fetch_assoc($filhos3)){
        array_push($filhos3,$filhos2);}
        $final2 = mysql_query("SELECT final_id FROM `interage` WHERE init_id='".$filhos3[0]."' AND number=1",$conn) or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');;
        $final3 = array ();
        while($final = mysql_fetch_assoc($final2)){
            array_push($final3,$final);}
        mysql_query("INSERT INTO TABLE `interage`(init_id,final_id,number) VALUES('".$key."','".$final3[0]."','".$i."')",$conn)or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');;
        }
        apanharfilhos($a,$i++);
        }
 
apanharfilhos($a,$i);
?>
Last edited by Benjamin on Thu May 07, 2009 9:19 pm, edited 1 time in total.
Reason: Changed code type from text to php.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Re: problem running function

Post by mickd »

Go through the code slowly and format the source nice and neatly so you can see which { belongs to which } clearly. Just having a quick look..

Code: Select all

 
    while($pais = mysql_fetch_array($pais1)) {
        $array1 = array();
        array_push($array1,$pais);
    }
 
For the above, did you intend to have $array1 = array(); inside the while loop?

P.S. You have a lot of ;; at the end of lines some lines.
Sosi
Forum Newbie
Posts: 9
Joined: Thu May 07, 2009 5:13 pm

Re: problem running function

Post by Sosi »

mickd wrote:Go through the code slowly and format the source nice and neatly so you can see which { belongs to which } clearly. Just having a quick look..

For the above, did you intend to have $array1 = array(); inside the while loop?
P.S. You have a lot of ;; at the end of lines some lines.
Cleaned the code a bit: although it doesnt run yet... now it even terminates before ending running (i.e. returns the "Connection to the web terminated before presenting the page" from mozilla). But the file 'config.php' is the same as it has allways been... I think the problem might be when reading the cicle - it doesnt insert the values in the table, but i dont know why... :(

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
 
include 'config.php';
 
$i=0;
$a=1;
function apanharfilhos($a,$i){
    global $i;
    global $a;
    
    $pais1 = mysql_query("SELECT init_id FROM `interage` WHERE number='".$i."' LIMIT 0, 70") or die('<hr />MySQL Error: '.mysql_error().'<hr />');
    
    
    
    $array1 = array();
    $filhos3 = array ();
    $final3 = array ();
    
    while($pais = mysql_fetch_array($pais1)){
        array_push($array1,$pais);
        }
        
    global $array1; 
    foreach($array1 as $key){
        $filhos3 = mysql_query("SELECT final_id FROM `interage` WHERE init_id='".$key."'") or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');
        
        while($filhos2 = mysql_fetch_assoc($filhos3)){
            array_push($filhos3,$filhos2);}
                
        while($final = mysql_fetch_assoc($final2)){
            $final2 = mysql_query("SELECT final_id FROM `interage` WHERE init_id='".$filhos3[0]."' AND number=1") or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');
            array_push($final3,$final);}
            
        mysql_query("INSERT INTO TABLE `interage`(init_id,final_id,number) VALUES('".$key."','".$final3[0]."','".$i."')",$conn)or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');}
        
    apanharfilhos($a,$i++);
        }
 
apanharfilhos($a,$i);
 
?>
Sosi
Forum Newbie
Posts: 9
Joined: Thu May 07, 2009 5:13 pm

Re: problem running function

Post by Sosi »

Sorry to keep asking, but can someone help me finding the problem in this please?
Thanks a lot
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: problem running function

Post by Benjamin »

Don't bump Sosi..
Forum Rules 1 1.1 4 wrote: 4. All users of any level are restricted from bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not receive a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.
Sosi
Forum Newbie
Posts: 9
Joined: Thu May 07, 2009 5:13 pm

Re: problem running function

Post by Sosi »

after some changes, I got this script:

Code: Select all

 
<?php
include 'config.php';
 
$i=0;
function apanharfilhos($i){
    global $i;
    
    $pais1 = mysql_query("SELECT init_id FROM `interage` WHERE number='".$i."'");
    
    $array1 = array();
    $filhos3 = array ();
    $final3 = array ();
    
    while($pais = mysql_fetch_array($pais1)){
        array_push($array1,$pais);
        }
        
    global $array1;
 
    foreach($array1 as $key){
        global $key;
        $filhos3a = mysql_query("SELECT final_id FROM `interage` WHERE init_id='".$key."'");
        $filhos3b = mysql_fetch_array($filhos3a);
        array_push($filhos3,$filhos3b);
        
        
        foreach($filhos3 as $filhos2){
            foreach($final2 as $final){
                $final2a = mysql_query("SELECT final_id FROM `interage` WHERE init_id='".$filhos2."' AND number=1");
                $final2b = mysql_fetch_array($final2a);
                array_push($final3,$final);
                $final3 = implode("", $final3);
                $array1 = implode("",$array1);
                settype($i,"integer");
                settype($key,"integer");
                foreach($item as $final3){
                settype($item,"integer");
                mysql_query("INSERT INTO TABLE `interage`(init_id,final_id,number) VALUES(".$key.",".$final3.",".$i.")");
            }}}}
            $count=count($array1);
            $search=array_search($key,$array1);
            if ($count<$search){apanharfilhos($i++);};
            else {return};
            }
 
apanharfilhos($i);
mysql_close($conn);
?>
However, it returns parse error at line "else {return};". Yet, I want the function to end its execution on else...

You guys have any idea?
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Re: problem running function

Post by mickd »

Code: Select all

 
else { return; }
 
Post Reply