Nodral Posted April 20, 2011 Share Posted April 20, 2011 Hi I have the following code and all is working except the ksort. If i remove it I get a list of approx 100 users with different userid's in no particular order. If I leave the ksort in, I get no user list. Any ideas? require_once "../config.php"; $sql = 'SELECT * FROM `mdl_scorm_scoes_track` WHERE scormid =338 AND element = "cmi.core.lesson_status"'; $sql = mysql_query($sql); while ($row = mysql_fetch_array($sql)){ switch($row['value']){ case "passed": $passed ++; break; case "completed": $completed++; break; case "incomplete": $getuser="SELECT firstname, lastname from mdl_user WHERE id = " . $row['userid']; $getuser=mysql_query($getuser); $getuser=mysql_fetch_array($getuser); $getuser = $getuser['firstname'] . " " . $getuser['lastname'] . " " . $row['userid']; $userfail[$row[userid]]=$getuser; break; default: $other++; break; } } $total = $passed + $incomplete + $completed; $incomplete = count($userfail); $total = $passed + $incomplete + $completed; $userfail=ksort($userfail); echo "Status showing as Completed (100% in test) = $completed out of $total<br/>"; echo "Status showing as Passed (80% in test) = $passed out of $total<br/>"; echo "Status showing as Incomplete (60% or less or not finished module) = $incomplete out of $total<br/>"; foreach ($userfail as $value){ echo "$value <br/>"; } Quote Link to comment https://forums.phpfreaks.com/topic/234229-ksort-not-working/ Share on other sites More sharing options...
Muddy_Funster Posted April 20, 2011 Share Posted April 20, 2011 Could you to a print_r on $userfail, also, I think you missed the single quotes from userid here : $userfail[$row[userid]]=$getuser; I'm not the best with arrays, so I'm not sure how much I can help. Quote Link to comment https://forums.phpfreaks.com/topic/234229-ksort-not-working/#findComment-1203926 Share on other sites More sharing options...
Nodral Posted April 20, 2011 Author Share Posted April 20, 2011 I need userid to be a number rather than a string, so I've removed the quotes. I did try it with quotes in, but it had the same result. (or lack of results!!) Quote Link to comment https://forums.phpfreaks.com/topic/234229-ksort-not-working/#findComment-1203927 Share on other sites More sharing options...
Muddy_Funster Posted April 20, 2011 Share Posted April 20, 2011 what did the print_r give out? as I said, i'm not the best with arrays, but I think by leaving out the quotes you are defining a constant rather than a variable (not an integer rather than a string) but I'm probably wrong :/. Quote Link to comment https://forums.phpfreaks.com/topic/234229-ksort-not-working/#findComment-1203928 Share on other sites More sharing options...
Nodral Posted April 20, 2011 Author Share Posted April 20, 2011 Cracked it. the ksort function does not return a new array, it acts on the existing array. Therefore the correct syntax is ksort($array) Cheers for your help tho muddy!! Quote Link to comment https://forums.phpfreaks.com/topic/234229-ksort-not-working/#findComment-1203932 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.