zgkhoo Posted November 7, 2007 Share Posted November 7, 2007 <?php function uplinepyramid($upline2){ echo "<br> enter function"; echo "<br> upline id=".$upline2; $result2=mysql_query("SELECT * from gamecard ORDER BY Serial"); while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){//finding match upline if($row2[serialnum]==$upline2){ echo "</br>upline id=".$row2[serialnum]; $upline3=$row2[upline]; $sql="INSERT INTO gptran (GpTID) VALUES ('$_POST[upline]')"; mysql_query($sql,$con); if(!empty($row2[upline])){// loop this function back uplinepyramid($upline3); }//enf if }//end if }//end while }//end function ?> output: enter function upline id=AAA0006 upline id=AAA0006 Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\xampplite\htdocs\EN\menu\UsrCard\usraddc.php on line 174 enter function upline id=AAA0001 upline id=AAA0001 Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\xampplite\htdocs\EN\menu\UsrCard\usraddc.php on line 174 Quote Link to comment Share on other sites More sharing options...
aschk Posted November 7, 2007 Share Posted November 7, 2007 Because you're performing another query inside the loop that uses mysql_fetch_array... Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 7, 2007 Author Share Posted November 7, 2007 then cant use mysql_fetch_array??? then wat should i use? thanks. Quote Link to comment Share on other sites More sharing options...
aschk Posted November 7, 2007 Share Posted November 7, 2007 You need to create arrays of the data before passing onto further calculations, and definitely don't use loopback (recursive) functions if you can avoid it. Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 7, 2007 Author Share Posted November 7, 2007 really cant use recursive for this ??? oh my god :-\ :-\ :-\ :-\ You need to create arrays of the data before passing onto further calculations, u meant passing all variable found into a array then...use another function to calculate? Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 7, 2007 Author Share Posted November 7, 2007 $sql="INSERT INTO gptran (GpTID) VALUES ('$_POST[upline]')"; mysql_query($sql,$con); if i remove the above code then the function working well, why? Quote Link to comment Share on other sites More sharing options...
aschk Posted November 7, 2007 Share Posted November 7, 2007 Try explaining what you're trying to do in english (no code). Because i have a funny feeling that you can do what you want in a few lines with no recursion. Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 7, 2007 Author Share Posted November 7, 2007 wat i want to do is....finding all the card's upline(tree mode db) from a reverse way, when find one upline then record its serial into a transaction table and record this upline earn 10 point .. like this downline->upline->upline->upline->upline->upline $sql = "CREATE TABLE gamecard ( Serialnum varchar(13), Serial varchar(13), Initial varchar(13), Activatecode varchar(13), Ownerid varchar(13), Status varchar(13), Downleft varchar(13), Downright varchar(13), Upline varchar(13), Expireddate datetime, Createdate datetime, Point integer(20), Golden varchar(15), Primary Key(Serialnum) )"; the cards table Quote Link to comment Share on other sites More sharing options...
aschk Posted November 7, 2007 Share Posted November 7, 2007 Also, what is $con ? Quote Link to comment Share on other sites More sharing options...
aschk Posted November 7, 2007 Share Posted November 7, 2007 Try this : <? // Recursive pyramid function. function uplinePyramid($upline){ // Array of data. $data = array(); // Grab all the game cards. $result = mysql_query("SELECT * from gamecard WHERE Serialnum = '{$upline}' ORDER BY serial"); // Have we got any results? if(mysql_num_rows($result) > 0){ // Build dataset. while($row = mysql_fetch_assoc($result)){ $data[] = $row; } } else { // Return from this function // i.e. no more upline??? return; } foreach($data as $d){ insertGptran($d['Upline']); uplinepyramid($d['Upline']); } } function insertGptran($upline){ // Insert info. $sql = "INSERT INTO gptran(GpTID) VALUES($upline)"; mysql_query($sql); } ?> Obviously you still need to define the initial upline/serial, and it recurses as you want. Now i'll take a look at your table. Any chance of some sample data? Quote Link to comment Share on other sites More sharing options...
aschk Posted November 7, 2007 Share Posted November 7, 2007 Ooh and if you could provide an expected resultset with your sample data that would be even better. I think there's a good possibility you can do it with a single SQL line. Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 7, 2007 Author Share Posted November 7, 2007 single SQL line???? wat u meant? how to do that? Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 7, 2007 Author Share Posted November 7, 2007 $con is from this opendb.php............ <?php // This is an example opendb.php $con = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); mysql_select_db($dbname,$con);// add $conn 1/9/07 ?> Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 7, 2007 Author Share Posted November 7, 2007 Try this : <? // Recursive pyramid function. function uplinePyramid($upline){ // Array of data. $data = array(); // Grab all the game cards. $result = mysql_query("SELECT * from gamecard WHERE Serialnum = '{$upline}' ORDER BY serial"); // Have we got any results? if(mysql_num_rows($result) > 0){ // Build dataset. while($row = mysql_fetch_assoc($result)){ $data[] = $row; } } else { // Return from this function // i.e. no more upline??? return; } foreach($data as $d){ insertGptran($d['Upline']); uplinepyramid($d['Upline']); } } function insertGptran($upline){ // Insert info. $sql = "INSERT INTO gptran(GpTID) VALUES($upline)"; mysql_query($sql); } ?> Obviously you still need to define the initial upline/serial, and it recurses as you want. Now i'll take a look at your table. Any chance of some sample data? cant put $sql = "INSERT INTO gptran(GpTID) VALUES($upline)"; into uplinepyramid(); function rite? but why? thanks Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 7, 2007 Author Share Posted November 7, 2007 i modified to below code. ..but the array data can echo inside this function,but when i echo after this function then become null. why? <?php function uplinepyramid($upline2,$arraycount){ echo "<br> enter uplinepyramid function"; echo "<br> upline id(variable)=".$upline2; echo "<br> array count=".$arraycount; $result2=mysql_query("SELECT * from gamecard ORDER BY Serial"); while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){//finding match upline if($row2[serialnum]==$upline2){ echo "</br>upline id(row)=".$row2[serialnum]; $upline3=$row2[upline]; $uplinepy[$arraycount]=$row2[serialnum]; $arraycount+=1; echo "</br>array in function=".$uplinepy[$arraycount]; //$sql="INSERT INTO gptran (GpTID) // VALUES // ('$_POST[upline]')"; // mysql_query($sql,$con); if(!empty($row2[upline])){// loop this function back uplinepyramid($upline3,$arraycount); }//enf if }//end if }//end while }//end function ?> Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 7, 2007 Author Share Posted November 7, 2007 bro, solution found! mysql_query($sql,$con); change to mysql_query($sql); ...but why? weird.. if mysql_query($sql,$con); then occur error msg Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\xampplite\htdocs\EN\menu\UsrCard\usraddc.php on line 212 but why? weird... ??? Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 7, 2007 Author Share Posted November 7, 2007 *bump* Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 7, 2007 Share Posted November 7, 2007 maybe $con is not a link resource or $con is not set as your connection Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.