LegendFTW Posted February 16, 2011 Posted February 16, 2011 Tried some more conversion but this time on a petshopcron heres v1: while($r=mysql_fetch_array($er)) { $petid[$r['itmid']]++; } $pet[0]=array_rand($petid, 1); $pet[1]=array_rand($petid, 1); Converted v2 while($r=$db->fetch_row($er)) { $petid[$r['itmid']]++; } $pet[0]=row_rand($petid, 1); $pet[1]=row_rand($petid, 1); Heres the error i get: Fatal error: Call to undefined function row_rand() in /home/damagedc/public_html/petshopcron.php on line 10 Quote
Equinox Posted February 16, 2011 Posted February 16, 2011 Change $pet[0]=row_rand($petid, 1); $pet[1]=row_rand($petid, 1); to $pet[0]=array_rand($petid, 1); $pet[1]=array_rand($petid, 1); Quote
LegendFTW Posted February 16, 2011 Author Posted February 16, 2011 thats what i thought u had to do keep it as array but i then got this error Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 10 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 11 and it goes on for all the arrays Quote
Equinox Posted February 16, 2011 Posted February 16, 2011 I don't know why you're going through the effort of just changing mysql_ to $db-> It works both ways and there are no benefits. Does it display the same error with this code? while($r=mysql_fetch_array($er)) { $petid[$r['itmid']]++; } $pet[0]=array_rand($petid, 1); $pet[1]=array_rand($petid, 1); Quote
LegendFTW Posted February 16, 2011 Author Posted February 16, 2011 ok i will just use it like that and the reason why i change it is because thats just how i learned to convert by replacing the mysql and array but if it works the same might as well not change Quote
LegendFTW Posted February 16, 2011 Author Posted February 16, 2011 used that code this is the error Fatal error: Call to undefined method database::fetch_array() in /home/damagedc/public_html/petshopcron.php on line 6 Quote
Blade Maker Posted February 16, 2011 Posted February 16, 2011 Does it work with the first code before you converted? Quote
Blade Maker Posted February 16, 2011 Posted February 16, 2011 Would you mind sending me the full code in the file through a private message so I can help? Quote
Kieran-R Posted February 16, 2011 Posted February 16, 2011 Would you mind sending me the full code in the file through a private message so I can help?Why a private message? Quote
Blade Maker Posted February 17, 2011 Posted February 17, 2011 Idk, he should have mentioned that it never worked before converting anyway..the errors are the random, it says it must be an array first so I think I know how to solve it. Just waiting on his reply. Quote
Diesl Posted February 17, 2011 Posted February 17, 2011 Are you sure you are actually fetching any data? From what I can see, the code is correct, but it could be that your array is empty. Use this to test while($r=mysql_fetch_array($er)) { $petid[$r['itmid']]++; } print_r($petid); Is anything being printed out? If it is, you should have something in the format of: ex. Array ( [1] => 1 [2] => 1 [5] => 1 [6] => 1 [7] => 1 [8] => 1 [9] => 1 ) If nothing is being printed, then your array is empty, and the problem is that you are not actually fetching any data (could be a problem with your SQL query, or that you haven't entered any content into your database). Quote
Djkanna Posted February 17, 2011 Posted February 17, 2011 used that code this is the error Fatal error: Call to undefined method database::fetch_array() in /home/damagedc/public_html/petshopcron.php on line 6 It's row not array, considering you're accessing the database class. Quote
lucky3809 Posted February 17, 2011 Posted February 17, 2011 Found your problem your converting the cron wrong it should be this from the top, didnt post the whole cron but you get the idea... Your changing array_rand to row_rand and it stays exactly the same for v2 also. require "globals.php"; global $c; $db->query("TRUNCATE TABLE pstock;"); $er=$db->query("SELECT * FROM items WHERE itmtype=9",$c); while($r=$db->fetch_row($er)) { $petid[$r['itmid']]++; } $pet[0]=array_rand($petid, 1); $pet[1]=array_rand($petid, 1); Quote
LegendFTW Posted February 18, 2011 Author Posted February 18, 2011 have tried both ways using row and array cause i did think it had to stay as array heres the error i got Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 10 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 11 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 12 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 13 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 14 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 15 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 16 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 17 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 18 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 19 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 20 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 21 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 22 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 23 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 24 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 25 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 26 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 27 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 28 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 29 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 30 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 31 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 32 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 33 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 34 Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/damagedc/public_html/petshopcron.php on line 35 and im just gonna post the full code so u can spot where it is im going wrong:S <?php require "globals.php"; global $c; $db->query("TRUNCATE TABLE pstock;"); $er=$db->query("SELECT * FROM items WHERE itmtype=9",$c); while($r=$db->fetch_row($er)) { $petid[$r['itmid']]++; } $pet[0]=array_rand($petid, 1); $pet[1]=array_rand($petid, 1); $pet[2]=array_rand($petid, 1); $pet[3]=array_rand($petid, 1); $pet[4]=array_rand($petid, 1); $pet[5]=array_rand($petid, 1); $pet[6]=array_rand($petid, 1); $pet[7]=array_rand($petid, 1); $pet[8]=array_rand($petid, 1); $pet[9]=array_rand($petid, 1); $pet[10]=array_rand($petid, 1); $pet[11]=array_rand($petid, 1); $pet[12]=array_rand($petid, 1); $pet[13]=array_rand($petid, 1); $pet[14]=array_rand($petid, 1); $pet[15]=array_rand($petid, 1); $pet[16]=array_rand($petid, 1); $pet[17]=array_rand($petid, 1); $pet[18]=array_rand($petid, 1); $pet[19]=array_rand($petid, 1); $pet[20]=array_rand($petid, 1); $pet[21]=array_rand($petid, 1); $pet[22]=array_rand($petid, 1); $pet[23]=array_rand($petid, 1); $pet[24]=array_rand($petid, 1); $pet[25]=array_rand($petid, 1); $db->query("INSERT INTO pstock VALUES('','','{$pet[0]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[1]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[2]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[3]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[4]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[5]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[6]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[7]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[8]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[9]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[10]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[11]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[12]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[13]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[14]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[15]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[16]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[17]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[18]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[19]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[20]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[21]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[22]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[23]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[24]}','','230000')"); $db->query("INSERT INTO pstock VALUES('','','{$pet[25]}','','230000')"); ?> Quote
lucky3809 Posted February 18, 2011 Posted February 18, 2011 Try taking off _rand delete all those then test the cron see if it works leave array there though. Quote
Blade Maker Posted February 18, 2011 Posted February 18, 2011 Yeah he has not replied to me in awhile though so idk whats up. Quote
Blade Maker Posted February 18, 2011 Posted February 18, 2011 $pet[25]=array_rand($petid, 1); $petid is the first argument right? so its saying it is not an array? lol I prob got this all wrong but w/e I don't use arrays to often. EDIT: Why is it like this, I am sure it works but why not do this: $petid = [$r['itmid']]++; or something is there a difference, please do not flame me I just barley use arrays. Quote
lucky3809 Posted February 18, 2011 Posted February 18, 2011 the error is saying there is no function of array_rand... the array is empty as Diesl mention... the $petid= part should be something like $petid=array("a"=>"Dog","b"=>"Cat","c"=>"Horse"); OR as Blade mention $petid = [$r['itmid']]++; $pet[0]=print_r(array_rand($petid,1)); $pet[1]=print_r(array_rand($petid,1)); Quote
Diesl Posted February 18, 2011 Posted February 18, 2011 @LegendFTW - Are you sure that you have items with itmtype=9 in your database? It still looks to me as if you are returning nothing and your array is empty. @lucky: that defeats the purpose of what he's doing. It would just declare an array inside another array and give an error when inputting into the databse. @blade: he is using this method because it randomizes which items will be put into pstock database. There are more efficient ways to do this, such as: $er=$db->query("SELECT itmid FROM items WHERE itmtype=9 ORDER BY rand() LIMIT 26",$c); while($r=$db->fetch_row($er)) { $db->query("INSERT INTO pstock VALUES('','','{$r['itmid']}','','230000')"); } However, the code he is using is still valid. Quote
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.