SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Something Simple Keep Getting A Parse Error

    I have the following:

    [php] while ($qry = mysql_fetch_array($results)) {
    if (strtotime($qry['loginDateTime']) <= (time() + 86400*31)) {
    $login .= 'Name: '.$qry["FirstName"].' '.$qry["LastName"].' ('.$qry["loginDateTime"].') '.$qry["Email"].'
    ';
    }[php] And I am trying to add the below in place of the "loginDateTime" $qry... I keep getting a parse error I think it's me not putting the ))) in the right spot... If anyone could help would be much appreciated!

    PHP Code:
     ($qry["loginDateTime"]?date("d/m/Y H:i:s"strtotime($qry["loginDateTime"])):'unknown'.) 

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2007
    Location
    Melbourne, Australia
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm not really sure what your trying to achieve but I can see you have a bracket in the wrong place.

    Try this:
    PHP Code:
    ($qry["loginDateTime"])?date("d/m/Y H:i:s"strtotime($qry["loginDateTime"])):'unknown' 

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I can see two opening curly braces and only one closing one, and that dot at the end of 'unknown' shouldn't be there. Try and separate it into chunks (makes it more readable too).
    PHP Code:
    $login .= 'Name: '.$qry["FirstName"].' '.$qry["LastName"].' (';
    $login .= $qry["loginDateTime"]?date("d/m/Y H:i:s"strtotime($qry["loginDateTime"])):'unknown';
    $login .= ') '.$qry["Email"].' '

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2007
    Location
    Melbourne, Australia
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm not really sure what your trying to achieve but I can see you have a bracket in the wrong place.

    Try this:
    PHP Code:
    ($qry["loginDateTime"])?date("d/m/Y H:i:s"strtotime($qry["loginDateTime"])):'unknown' 
    breakdown of ternary IMO

    (expression)?true result:false result

  5. #5
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You don't need the brackets in the bit before the question mark in the ternary unless it's very complex (which it isn't in this case). I think the bigger problem is putting it in the middle of a string concatenation.

  6. #6
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So if I were to put it all together would this be correct?

    PHP Code:
    while ($qry mysql_fetch_array($results)) {  
          if (
    strtotime($qry['loginDateTime']) <= (time() + 86400*31)) {  
             
    $login .= 'Name: '.$qry["FirstName"].' '.$qry["LastName"].' ('.$qry["loginDateTime"]?date("d/m/Y H:i:s"strtotime($qry["loginDateTime"])):'unknown')   '.$qry["Email"].'  
    ';  
          } 

  7. #7
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well... try it. While loop still appears to be missing a closing curly brace though.

  8. #8
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Raffles, Hmmm not sure what happened, ok I did it your way and that has worked... But the only issue now is that previously the code generated each 'member' on a seperate line... Now they are just one after the other all on one big line... Any ideas?

  9. #9
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what I mean previously it displayed the data like this

    Name: John Smith (18/03/2007 12:30:41) john.smith@yahoo.com
    Name: John Smith (18/03/2007 12:30:41) john.smith@yahoo.com
    Name: John Smith (18/03/2007 12:30:41) john.smith@yahoo.com
    Name: John Smith (18/03/2007 12:30:41) john.smith@yahoo.com
    Name: John Smith (18/03/2007 12:30:41) john.smith@yahoo.com
    Name: John Smith (18/03/2007 12:30:41) john.smith@yahoo.com
    Name: John Smith (18/03/2007 12:30:41) john.smith@yahoo.com
    Name: John Smith (18/03/2007 12:30:41) john.smith@yahoo.com
    But now it displays it like this all on the same line...

    Name: John Smith (18/03/2007 12:30:41) john.smith@yahoo.comName: John Smith (18/03/2007 12:30:41) john.smith@yahoo.comName: John Smith (18/03/2007 12:30:41) john.smith@yahoo.comName: John Smith (18/03/2007 12:30:41) john.smith@yahoo.comName: John Smith (18/03/2007 12:30:41) john.smith@yahoo.comName: John Smith (18/03/2007 12:30:41) john.smith@yahoo.comName: John Smith (18/03/2007 12:30:41) john.smith@yahoo.comName: John Smith (18/03/2007 12:30:41) john.smith@yahoo.com

  10. #10
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, this is not PHP's fault. I don't know why the first case put it all on different lines, but at the end of $login you need to add a newline, "\n", or if it's HTML, you need to put each item in a list (<ul> most likely).


Bookmarks

Posting Permissions

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