Closed Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: Display Admin Link

  1. #1
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Display Admin Link

    Hey

    Iv been trying to get my blog system to display a Login In Admin Center link but I cant seem to get it to work

    Iv been trieing to get it to display the link if the field in the SQL database says 'Yes' the field is called admin

    Code:
    //DISPLAY ADMIN LINK
    	$result = mysql_query("SELECT * FROM regusers WHERE admin='$admin'");
    
    	if(mysql_result($admin) == yes) {
    		//echo "Test";
    		//}else{
    	}
    It dosent seem to work though

    Anyone help me!?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    webcodez's Avatar
    webcodez is offline Programmer
    Join Date
    Feb 2010
    Posts
    148
    Rep Power
    0

    Re: Display Admin Link

    First off in the query you supplying you search for a row where the field admin is equal to the value of the variable $admin. Why is this? Because as from your description you want to check whether the field 'admin' is set to 'yes' and not to '$admin', Maybe you set the wrong field inside the query where clause?

    Another thing is I don't get what you're trying to achieve with ' mysql_result($admin)' ?

    And what row needs to have the field ' admin ' set to ' Yes '? As now you're checking a field on all rows which isn't really what you're meaning to do I suppose.
    Last edited by webcodez; 02-16-2010 at 08:25 AM.

  4. #3
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Re: Display Admin Link

    This would explain why its not working.

    Fail!

    How would I achieve this then?

  5. #4
    webcodez's Avatar
    webcodez is offline Programmer
    Join Date
    Feb 2010
    Posts
    148
    Rep Power
    0

    Re: Display Admin Link

    Well, is it an option you want to be able to be set to 'Yes' or 'No'? Just a global option?
    So when this option is set to 'Yes' the admin link is shown, if set to 'No' it's hidden?
    Because in that case it shouldn't be a field of the 'regusers' table which I assume to be having a list of all members (rows), and this option would just require ONE row, as it's just a global option in that case, with one value ( not varying for different members or something ).

    let me know, so I can see if we're on the same line
    Last edited by webcodez; 02-16-2010 at 08:25 AM.

  6. #5
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Re: Display Admin Link

    Yeah Thats Right

    The Database Holds The Passwords, Email and Username with the Admin Field Display Either Yes or No

    If Yes Display the link
    if no dont.

    Easyer to edit in the admin panel then!

  7. #6
    webcodez's Avatar
    webcodez is offline Programmer
    Join Date
    Feb 2010
    Posts
    148
    Rep Power
    0

    Re: Display Admin Link

    Yes, well but you don't want to set the Admin field to Yes or No for all new users as well right? As it's user 'independent', not depending on what user, it's a global option you want to set so it would be weird to set it for each user and beside that it would be able to cause errors as it will select only ONE row (member) its value for the field 'Admin', so when there are more members with different values for that field it can lead to errors/selecting the wrong value.

    So what I'd suggest is creating another table with all options for your blog, which can beside this option as well provide you the ability to add & check more options for your blog easily.

    Example of table:
    Table name: options
    field1
    name: ID
    type: 250(INT)
    auto-increment & Primary Key
    field2
    name: opt_name
    type: 20(VARCHAR)
    field3
    name: opt_value
    type: 250(VARCHAR)

    Add a row for the 'admin' option
    Set: field 'opt_name' = 'admin' , 'opt_value' = 'Yes' (or 'No')

    Example of script:

    Code:
    <?php

    $check_admin 
    mysql_query("SELECT opt_value FROM options WHERE opt_name = 'admin' "); //select the value of the option 'admin'
    $opt_admin mysql_fetch_assoc($check_admin); //get the result
    $opt_admin $opt_admin['opt_value']; //get the value of the option 

    if($opt_admin == 'Yes') {

       
    //show the link

    }
    ?>
    It's also possible in another way, by adding inside the WHERE clause: & opt_value = 'Yes'
    And then just counting the rows found as result using mysql_num_rows. If this results in a number higher than 0 ( if properly done it should be 0 or 1, 1 if the row was foujnd with as value 'Yes', 0 if the rows wasn't found with the value 'Yes' ( so it contains another value: 'No' assumed )).

    2nd method:

    Code:
    <?php

    $check_admin 
    mysql_query("SELECT opt_value FROM options WHERE opt_name = 'admin' AND opt_value ='Yes' "); //select the value of the option 'admin'
    $opt_admin mysql_num_rows($check_admin); //count the rows found

    if($opt_admin 0) { //if any rows where found with option name = 'admin' and option value 'Yes'

       //show the link

    }
    ?>
    ANOTHER method would be using COUNT, but I guess 2 methods is enough
    Just use one of them and you should be fine .

    Table SQL

    Code:
    CREATE TABLE IF NOT EXISTS `options` (
      `
    idint(250NOT NULL AUTO_INCREMENT,
      `
    opt_namevarchar(20NOT NULL,
      `
    opt_valuevarchar(250NOT NULL,
      
    PRIMARY KEY (`id`)
    ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=;

    INSERT INTO `options` (`id`, `opt_name`, `opt_value`) VALUES
    (1'admin''Yes'); 
    Note: Would rather use something like 0 or 1 to indicate the admin field to be 'Yes' (true = 1) or 'No' (false = 0), but doesn't matter too much I guess.
    Last edited by webcodez; 02-16-2010 at 08:24 AM.

  8. #7
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Re: Display Admin Link

    Thanks so much for your help!!

    So would i need to re integrate username and a password field into this new table for it to work?!

    I'll let you know if it works!

  9. #8
    webcodez's Avatar
    webcodez is offline Programmer
    Join Date
    Feb 2010
    Posts
    148
    Rep Power
    0

    Re: Display Admin Link

    You're Welcome

    No there's no need to integrate any username or password field as it's just a global option. It's not working different for different users right? So no need to put username or password field as it hasn't got anything to do with it.
    Last edited by webcodez; 02-16-2010 at 08:24 AM.

  10. #9
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Re: Display Admin Link

    Sorry for sounding abit of an idiot here

    But how would I then set that global option for a user?

    Imagine if you was an Admin on this forum, the Admin Link shows up because another Admin has made you an Admin, but if you are a regular member, it wont.

    I'm also guessing I could put the PHP code in a separate PHP File and include it on the pages its needed

    I could also incorporate it to only show parts of the admin section if you are an admin?


    Thank's!!
    Last edited by Bioshox; 02-16-2010 at 07:11 AM.

  11. #10
    webcodez's Avatar
    webcodez is offline Programmer
    Join Date
    Feb 2010
    Posts
    148
    Rep Power
    0

    Re: Display Admin Link

    Then what you want to do is check 2 things: Whether the user logged in is an Admin, and whether the global option to show the admin link for admins is set to 'Yes' right?

    Or you just want to show the admin link for admins always? (or depending on whether this global option is set to 'Yes' or 'No'?)

    EDIT: in the first case you would want to set a field like 'Role' for each user. Then you could have for example '1' representing the role of an administrator, value '2' representing the role of a moderator, role '3' representing the role of a normal member - for example. Then all you'd need to do is check the role of the currently logged in user. If he's got the role of a admin ( or moderater for example, if you want these to allow the admin section as well ) then show the link. If this is what you want to do, let me know and I'll write an example .

    EDIT2:

    Example:

    Code:
    <?php
    session_start
    ();

    //assuming the username of the user logged in is put in $_SESSION['username']

    $get_role mysql_query("SELECT role FROM accounts WHERE username = '".$_SESSION['username']."' ");
    $get_role mysql_fetch_assoc($get_role);
    $role $get_role['role'];

    if(
    $role == '1') { //if the user is an administrator

       //show admin link

    }

    ?>
    Then for the register system you should by default add the value 0 or 3 ( all depends on what you want to represent the role of a normal user of ) when creating a new normal user account.

    You could also expand it more by creating another table with all roles and priveleges but that's however more advanced to do but same idea.

    If you only want to show the admin links for admin users when the global option 'admin_link' is set to 'Yes' as well (for example), you could have a script like this:

    Example:

    Code:
    <?php
    session_start
    ();

    //assuming the username of the user logged in is put in $_SESSION['username']

    $get_option mysql_query("SELECT opt_value FROM options WHERE opt_name = 'admin_link' ");
    $get_option mysql_fetch_assoc($get_option);
    $option       $get_option['opt_value']; //value of global option 'admin_link' which allows you to define whether to show an admin links for admins or not


    //show any admin link at all if administrator logged in? :
    if($option == 'Yes') {  //yes -> check if user logged in is an admin

    $get_role mysql_query("SELECT role FROM accounts WHERE username = '".$_SESSION['username']."' ");
    $get_role mysql_fetch_assoc($get_role);
    $role $get_role['role'];

    if(
    $role == '1') { //if the user is an administrator

       //show admin link

    }

    }

    ?>
    Now use the SQL of the previous post and add a field 'role' to the user accounts table, and should work

    If this isn't what you meant either just tell me

    Hope this helped,

    Cheers.
    Last edited by webcodez; 02-16-2010 at 08:24 AM.

Closed Thread
Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 11-01-2011, 04:01 PM
  2. Link wheels ? Link generations ?
    By genux in forum Search Engine Optimization
    Replies: 3
    Last Post: 05-08-2011, 07:01 AM
  3. Link to display uploaded image(s)
    By batowiise in forum PHP Development
    Replies: 0
    Last Post: 01-11-2011, 06:29 AM
  4. New Admin?
    By TcM in forum The Lounge
    Replies: 4
    Last Post: 12-07-2006, 09:39 AM
  5. Welcome to our new admin
    By Jordan in forum The Lounge
    Replies: 2
    Last Post: 07-15-2006, 10:21 AM

Tags for this Thread

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