SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Query dynamic pages for page title

    Hi,

    I am a complete newb when it comes to mysql so I thought I would seek out some help here.

    Anyway, my problem is I want to be able to put a page title on pages I have created.

    For instance I have created a page and called it "Advanced Menu Generator" and this pages id is 17.

    I can get the page title this way:
    SELECT `page_title`
    FROM `created_pages`
    WHERE `pid` ='17'

    Which would be fine if I only had a few pages but I have a lot of pages and they are growing.

    So what I need to know is how to capture the page id from page.php?page=17 on the fly and insert it into the query and then insert the result into $page_name and have something like $page_title = $lang['page_name''] .' - ' . $page_name;


    I hope someone can understand what I mean and help me out with this
    At the moment all my pages are titled -Home- which sorta sucks :P

  2. #2
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're accessing the page as page.php?page=17, then $_GET['page'] will equal 17. Then you can plug that value into the query (after being cleaned/stripped/etc., of course).

  3. #3
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.. that pointed me in the right direction..
    Now back to breaking the website

  4. #4
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oook, after many hours of breaking the site I have given up and am seeking help again.

    I've managed to get it to put the right page id in with the $_GET function that was suggested above but I haven't figured out how to plug it into the query and have it output the new result.


    $p_id = $_GET['page'];
    $p_name = "SELECT 'pagename' FROM 'pages' WHERE 'lid'='$p_id'";
    $page_title = "[$p_name]";

    Obviously I don't really have a clue what I am doing :P
    But I get the result of [SELECT 'pagename' FROM 'pages' WHERE 'lid'='17']

    I just haven't figured out how to actually make it query the database so I get the real result of the query instead of the query being printed to the title of the page.


    I'm sure I am missing a lot to make this work so if anyone can give me an example of a working piece of code I would really appreciate it.

  5. #5
    SitePoint Guru defiance's Avatar
    Join Date
    Oct 2004
    Location
    United states
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have to send the query to mysql database, then fetch the result

    $p_id = $_GET['page'];
    $p_name = "SELECT 'pagename' FROM 'pages' WHERE 'lid'='$p_id'";
    $result = mysql_query($p_name);
    $row = mysql_fetch_array($result);

    $page_title = $row[yourfieldname];


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
  •