Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation PHP Code into PHP Code (if)

    Hi Guys!

    i need help, how can i add php code into php code?

    Add code:


    PHP Code:
    <?php echo session->userinfo['id'];?>  // This code: User's ID see

    PHP Code:
    <?php

    if($session->userinfo['id']== ** HERE ADD **)
    echo 
    $notes
    else
    echo 
    " - content message - ";

    ?>
    Thanks!

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    I at least have no idea what you mean by "add php code into php code". What are you trying to add where?

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Keleth View Post
    I at least have no idea what you mean by "add php code into php code". What are you trying to add where?
    Hi Keleth thanks for the reply..

    ** Here Add ** =
    i wish code: <?php echo session->userinfo['id'];?>

    PHP Code:
    if($session->userinfo['id']== $session->userinfo['id']) // Not working.. 
    where something is wrong?

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Not working how? That will always return true, btw.

  • #5
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    Not working how? That will always return true, btw.
    PHP Code:
    <?php $session->userinfo['id']; ?>
    -> User's ID Show

    user to see the contents of their own:

    PHP Code:
    <?php
    if($session->userinfo['id']==2)
    echo 
    $notes
    else
    echo 
    " - no user's details - ";
    ?>
    (sample: user ID 2)
    OK! working..

    ----

    PHP Code:
    <?php
    if($session->userinfo['id']==$session->userinfo['id'])
    echo 
    $notes
    else
    echo 
    " - no user's details - ";
    ?>
    but not work

    (i sorry, English is not advanced )

  • #6
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Pages: OK
    DB Tablo: OK
    User Interface: OKbut
    user-specific show: No

    I want do to:



  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Without knowing the workings of the rest of your code, just try this:

    Code:
    <?php
    if ($session->userinfo['id'])
    {
        echo $notes; 
    }
    else
    {
        echo " - no user's details - ";
    }
    ?>

    That is assuming that you are setting $session->userinfo['id'] to something like 0 or false if the current user is not logged in. If that does not work, you will need to provide more information regarding your code for further suggestions.

  • #8
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    Without knowing the workings of the rest of your code, just try this:

    Code:
    <?php
    if ($session->userinfo['id'])
    {
        echo $notes; 
    }
    else
    {
        echo " - no user's details - ";
    }
    ?>

    That is assuming that you are setting $session->userinfo['id'] to something like 0 or false if the current user is not logged in. If that does not work, you will need to provide more information regarding your code for further suggestions.

    Thanks for answer..

    showed that all the notes..

    Other Codes:


    notes.php (header codes)

    PHP Code:
    <?php

    // Error reporting:
    error_reporting(E_ALL^E_NOTICE);

    // Removing notes that are older than an hour:
    mysql_query("DELETE FROM notes WHERE id>3 AND dt<SUBTIME(NOW(),'0 1:0:0')");

    $query mysql_query("SELECT * FROM notes ORDER BY id DESC");

    $notes '';
    $left='';
    $top='';
    $zindex='';

    while(
    $row=mysql_fetch_assoc($query))
    {
        
    // The xyz column holds the position and z-index in the form 200x100x10:
        
    list($left,$top,$zindex) = explode('x',$row['xyz']);

        
    $notes.= '
        <div class="note '
    .$row['color'].'" style="left:'.$left.'px;top:'.$top.'px;z-index:'.$zindex.'">
            '
    .htmlspecialchars($row['text']).'
            <div class="author">'
    .htmlspecialchars($row['name']).'</div>
            <span class="data">'
    .$row['note_id'].'</span>
        </div>'
    ;
    }
    ?>
    class_users.php

    PHP Code:
        /**
           * User::getUserInfo()
           * 
           * @param mixed $username
           * @return
           */
          
    function getUserInfo($username)
          {
              global 
    $db;
              
    $sql "SELECT * FROM users WHERE username = '" $db->escape($usernametrue)."'";
              
    $result $db->query($sql);
              if (!
    $username) {
                  return 
    false;
              }
              
              if (
    mysql_num_rows($result) > 0) {
                  
    $row $db->fetch($result);
                  return 
    $row;
              } else
                  return 
    null;
          }
          
          
    /**
           * User::getUserById()
           * 
           * @param mixed $id
           * @return
           */
          
    public function getUserById($id)
          {
              global 
    $db;
              
    $sql "SELECT * FROM users WHERE id = '" . (int)$id "'";
              
    $row $db->first($sql);
              
              if (
    $row) {
                  return 
    $row;
              } else
                  return 
    0;
          }

          
    /**
           * User::getUserList()
           * 
           * @return
           */
          
    public function getUserList()
          {
              global 
    $db;
              
    $sql "SELECT id, username,email FROM users ORDER BY username";
              
    $row $db->fetch_all($sql);
              
              if (
    $row) {
                  return 
    $row;
              } else
                  return 
    0;
          } 
    I added the correct codes?

  • #9
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Try changing this line in notes.php:

    Code:
    $query = mysql_query("SELECT * FROM notes ORDER BY id DESC");
    to:

    Code:
    $query = mysql_query('SELECT * FROM notes WHERE id='.intval($session->userinfo['id']));

  • Users who have thanked MattF for this post:

    emsanator (11-04-2010)

  • #10
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    Try changing this line in notes.php:

    Code:
    $query = mysql_query("SELECT * FROM notes ORDER BY id DESC");
    to:

    Code:
    $query = mysql_query('SELECT * FROM notes WHERE id='.intval($session->userinfo['id']));
    Excellent!! MattF, Thank you so much! Now working..

  • #11
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    You're welcome. Glad to hear that sorted it.


  •  

    Posting Permissions

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