Page 1 of 1
problem running function
Posted: Thu May 07, 2009 5:33 pm
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 />');;
}
}
?>
Re: problem running function
Posted: Thu May 07, 2009 6:59 pm
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.
Re: problem running function
Posted: Thu May 07, 2009 7:14 pm
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!
Re: problem running function
Posted: Thu May 07, 2009 7:42 pm
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);
?>
Re: problem running function
Posted: Thu May 07, 2009 10:11 pm
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.
Re: problem running function
Posted: Fri May 08, 2009 4:36 am
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);
?>
Re: problem running function
Posted: Fri May 08, 2009 8:38 am
by Sosi
Sorry to keep asking, but can someone help me finding the problem in this please?
Thanks a lot
Re: problem running function
Posted: Fri May 08, 2009 9:46 am
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.
Re: problem running function
Posted: Sun May 10, 2009 3:17 pm
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?
Re: problem running function
Posted: Sun May 10, 2009 10:36 pm
by mickd