Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2007
    Thanked 0 Times in 0 Posts

    Unhappy only show records for the user logged in

    I only want to display the records that are assignedto user currently logged in?!
    the error i get is: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /display1.php on line 18

    $result = mysql_query("SELECT * FROM assessment WHERE ".$_SESSION["login"]." = assignedto ORDER BY Dateadded DESC ");

  2. #2
    Regular Coder
    Join Date
    Apr 2007
    Camarillo, CA US
    Thanked 83 Times in 82 Posts
    Unless the value of $_SESSION['login'] is an integer, that's an invalid query. You must wrap all string values in quotes (it doesn't hurt to wrap integers in quotes either - MySQL knows what to do with them). The comparison is also backwards. I don't know that I've ever seen it written that way, I suppose it would work, I haven't tested it.

    Your code should be written as
    PHP Code:
    $query"SELECT * FROM assessment
                WHERE assignedto =  '
                ORDER BY Dateadded DESC"
      OR die( 
    "QUERY ERROR:<br />{$query}<br />" .mysql_error() ); 
    Notice four things:
    • Separation of the SQL statement from the query call. You can then take that string and display in the browser, send to a log, etc.
    • That you can use whitespace to better organize your SQL statements. I'm fond of using HEREDOC syntax when the mood strikes.
    • The use of {braces} to wrap the array variable. I typically use these when including variables in strings that need to be evaluated, but it's essential to properly evaluate $array['indexes'].
    • Use of the old standby die() to kill the script and send an error message. Note this should only be done while developing. A "live" server should only ever handle errors gracefully, present the user will a full document while silently logging the error for you.

  3. Users who have thanked bdl for this post:

    jarv (05-16-2008)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts