Jump to content

Nodral

Members
  • Posts

    397
  • Joined

  • Last visited

Everything posted by Nodral

  1. 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!!
  2. 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!!)
  3. Hi What exactly are you trying to acheive? This script looks fine but obviously we need to know the purpose. Are you getting an error? Stu
  4. Ok Once the user is logged in, you need to pull the userid from the user table. I'd add this into the login script and declare it to a session variable so it can be used wherever you need. <?php $LoginRS__query=sprintf("SELECT username, password, userid FROM users WHERE username=%s AND password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $pwnedbook) or die(mysql_error()); $userid=mysql_fetch_array($LoginRS); $_SESSION['userid']=$userid['userid']; I think this should work, you now have a session variable $_SESSION['userid'] which carries their userid and you can use this all over your scripting. Stu
  5. Hi Try moving the variable out of the brackets and concatenating it. I have the same issue sometimes and find that when usingf a variable from an array it crashes. <?php require_once('connect.php'); $query = mysql_query("SELECT * FROM user WHERE username = " . $_SESSION[gatekeeper]); Stu
  6. 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/>"; }
  7. Hokey Pokey Where does the userid come from? How do you identify when a user is logged in etc? You'd need to use this to get the userid from the user table, then writing it into the comments table is fairly straight forward. Stu
  8. I agree that this is shown in the code, however $id is then redefined as $_POST['id']. This implies that it is being taken from an HTML form that the user completes. $id=$_POST['id'];
  9. All sorted, just spotted a missing bracket
  10. Hi I'm assuming that the variable $id is the userid? If so, it looks as though this is written with the comment $sql=mysql_query("insert into comments(comment,msg_id_fk)values('$comment','$id')"); this basically says write into comments table the comment ($comment) and the id ($id). If this is incorrect, we'd need the structure of your user table to create the SELECt statement to pull the user id and write with the comment. Stu
  11. Hi All Can anyone give me any pointers as to why I'm getting the following error from the code below? <?php require_once "../config.php"; $sql = 'SELECT value 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 "incomplete": $incomplete++; break; case "completed": $completed++; break; default: $other++; break; } } echo "Passed = $passed <br/>"; echo "Incomplete = $incomplete <br/>"; echo "Completed = $completed <br/>"; echo "Others = $other<br/>"; ?> Parse error: syntax error, unexpected T_CASE in D:\Documents\AI24\Web\skooch\dccout\index.php on line 8 Cheers in advance guys
  12. Hi You could try using the rawurlencode() & rawurldecode() functions. Surely this would be a better way forward? I'm new to php myself so apologies if this isn't 100% correct, but it's just another train of thought for you. $input=$_GET['input']; $CNE = rawurlencode($input);
  13. Hi Can you give a copy of the error you're getting plz
  14. Can you post the form code and also the query you are running. As it stands there is too much code missing to be able to decue where the error is. Have you actually run $query as a mysql_query?
  15. Hi I have 3 tables in my DB which I am trying to interrogate. mdl_feedback_completed has columns id, feedback, userid, timemodified mdl_feedback_tracking has columns id, userid, feedback, completed mdl_feedback_value has columns id, course_id, item, completed, value. These tables are already set up as part of a Moodle installation and I cannot modify them. The query I am trying to run should select value from mdl_feedback_value depending on the timemodified field in mdl_feedback_completed. However, the query is timing out and I get a fatal error. Any ideas? $sql="SELECT mdl_feedback_value.value FROM mdl_feedback_value INNER JOIN mdl_feedback_tracking ON mdl_feedback_value.completed = mdl_feedback_tracking.completed INNER JOIN mdl_feedback_completed ON mdl_feedback_tracking.feedback = mdl_feedback_completed.feedback WHERE timemodified = 1301499189";
  16. Hmmmm I'm trying to develop a chat application for an internal site. Looks like it'll have to be permanent tables then. Is there a way I can 'time-out' a user and then drop the table after say an hour? Sorry, again, very new to MySQL
  17. So if User A connect to the DB and creates a Temp Table, can User B then connect to DB and view that Temp Table until User A disconnects? Sorry if I sound a bit thick on this!!
  18. Here's a simple question which will save me hours of Googling. When User A creates a temporary table which User B can interact with, When does the temporary table get dropped? Is it:- a) When User A chooses to drop it or when he no longer interacts with it (if so, what is the timeframe on this) b) When User A AND User B no longer interact with the table (if so, what is the timeframe on this) Basically I need to know how the 'ownership' of a temporary table works. Cheers Guys
  19. Hi all I'm writing a little chat application so my users can contact an expert via an IM system. I'm pretty much through the planning stage and have most of the code worked out (in my head!!) as to how I can do this. However, the one bit I can't get my head around is how to write to a DB table if a user closes their browser instead of logging out. I've very little Javascript knowledge (my way of saying none!!) and would like some kind person to talk me through in laymans terms how to set this up. The process I would like to happen is user logs in and php changes field in DB table to show user/expert is online user has chat session user logs out (or closes browser) and php changes field in DB table to show user/expert offline The other reason for this being written to a DB table is in the future it will be developed to show when users/experts are busy and involved in discussions. Any help you guys can offer would be greatly appreciated. It's also been suggested that I use Temporary Tables. Can anyone give me a quick overview of these and how they would function. Would both users need to log out/close browsers to delete the tables or just one?
  20. I can do this for example SELECT mdl_question.id, questiontext FROM mdl_question INNER JOIN mdl_quiz_question_instances ON mdl_question.id = question INNER JOIN mdl_quiz ON mdl_quiz_question_instances.quiz = mdl_quiz.id WHERE course = 233. But how do I SELECT from 2 Tables, eg SELECT Name (from table A) AND SELECT address (from table B) WHERE id = 6 (in table A) AND id = 12(in Table B)
  21. I can do a JOIN. What I don't undderstand is how to extract data from 2 table based on the same conditons. ie if conditions in rows in tables a & b are true, extract line data from tables b & c
  22. Hi You simply need a full stop <?php $assignment_id=$_GET['assignment_id']; echo $row['question_id'] . $assignment_id; ?> If you want a space between them when they echo out just use the following echo $row['question_id'] . " " . $assignment_id;
  23. Ok, i'm pretty new to this, but it seems like you are trying to perform an IF test and define a variable in the same line. See if the following makes sense. Perform the test, then if TRUE, define the $getkey variable? if(array_search($tbls_res['Field'],$data)) { $getkey = $tbls_res['Field']; array_push($fieldarray,$tbls_res['Field']); array_push($keyarray,$getkey); } else { echo ""; } }
  24. Try function GetUser($user) { $qFindUser = "SELECT * FROM members WHERE email = '$user'"; $rFindUser = mysql_query($qFindUser) or die (mysql_error()); $UserInfo = mysql_fetch_array($rFindUser); return $UserInfo; } This way you are just defining the fuction as requiring a variable called $user which it will pass into itself. I don't know what the ="" is for but that may be causing you an issue.
  25. Hi Try putting an extra = sign in the if test. currently you are redefining the variable whereas if you have == this will compare the two. ie if($getkey == array_search($tbls_res['Field'],$data))
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.