Jump to content

Nodral

Members
  • Posts

    397
  • Joined

  • Last visited

Posts posted by Nodral

  1. 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

  2. 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

  3. 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/>";
    }

  4. 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

  5. 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

     

  6. 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);
    

  7. 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";

  8. 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

  9. 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

     

     

     

    • 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

    1. user logs in and php changes field in DB table to show user/expert is online
    2. user has chat session
    3. 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?

  10. 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)

  11. 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;
    

  12. 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 "";					}						}
    

  13. 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.

×
×
  • 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.