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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: query help

  1. #1
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts

    query help

    hi i am using this piece of code to display my pages example.com/users/profile.php?id=5

    PHP Code:
    $res=mysql_query('SELECT * FROM users WHERE u_id="'.mysql_real_escape_string($_GET['id']).'"'); 
    and it works fine but i want to add another level "i guess you could call it" and i want to make the links look something like this "doesnt matter" example.com/users/profile.php?id=5&title=whatever

    the example.com/users/profile.php?id=5 would be the profile link but i need something like &title=whatever to show other pages created by the user. title= would db info for whatever entry they may add. cann someone help me? thanks.

    sorry if you dont understand this im having trouble explaining it.

  • #2
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Do you have a database table for the pages they have created if so could you post the sql dump so we can see it.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #3
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DJCMBear View Post
    Do you have a database table for the pages they have created if so could you post the sql dump so we can see it.
    no this is just a test on localhost. i just want to be able to add something like &title=whatever

    the row would have user_id, post_id, and title_id

    i would use the page title=whatever to grab the assosiated user and posts from them already in the db.

  • #4
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    why dont you just use the id as im guessing the profile id matches up with the users id, so why not use that and in the url have
    ?id=5&section=other_pages

    And in php do an if statement like this
    PHP Code:
    if($_GET['section'] == "other_pages")
    {
      
    // Show all other pages for this user id
    }
    else
    {
      
    // Do the current code

    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #5
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DJCMBear View Post
    why dont you just use the id as im guessing the profile id matches up with the users id, so why not use that and in the url have
    ?id=5&section=other_pages

    And in php do an if statement like this
    PHP Code:
    if($_GET['section'] == "other_pages")
    {
      
    // Show all other pages for this user id
    }
    else
    {
      
    // Do the current code

    that is a good idea. i just need to figure out a way to make this work. i will have to mess with this for a bit.

  • #6
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    If you need any more help on the just post your question here.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #7
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DJCMBear View Post
    If you need any more help on the just post your question here.
    i cant seem to figure this out. maybe i will leave this for another time.

  • #8
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    this is the code that is making it example.com/users/profile.php?id=3

    PHP Code:
    <?php

    $res
    =mysql_query('SELECT u_username,u_full_name FROM users WHERE u_id="'.mysql_real_escape_string($_GET['id']).'"');
     
    if(
    mysql_num_rows($res) != 1)//no user with that username exists
    {
    echo 
    "<script language=\"Javascript\" type=\"text/javascript\">
        alert(\"This user does not exist\")
        document.location.href='index.php'</script>"
    ;
    }
    else
    {
        
    $row=mysql_fetch_assoc($res); //pull the users info
    }
    ?>
    pretty simple code, but i cant figure out how to make the section part at the end work with it.

    the column 'section' is in is "posts".

    im trying to make it so a user can create a new page for text content and name it whatever they want. so the name would be something like example.com/users/profile.php?id=3&section=example

    "example" would be the name in the 'section' column in the db

    so when someone goes to the page example.com/users/profile.php?id=3&section=example they see all of the assosiated content for that page using post ids and user ids.
    Last edited by cosmicsea; 05-30-2010 at 05:29 PM.

  • #9
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    So if I understand corrently you want the user to make a page and they can see all their own posts and other information about themselfs?

    Or

    The user can make a page and put any text on it they want and others can goto it and see that text like lets say i made a page and called it hello world and wrote hello there world, if a user goes to profile.php?id=123&section=hello_world they could then see the text hello there world?
    Last edited by DJCMBear; 05-30-2010 at 05:56 PM.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #10
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    I am going to try to make what im trying to do more clear. I am going to make a form for "section" and this will be where the user inputs what the page will be named "coolstuff" ie: example.com/users/profile.php?id=3&section=coolstuff and also on the form will be inputs for text, so when the info goes to the db table "posts" it will go in 1 row with user_id, post_id, and the "section name". I am trying to make it so all the posts in this section ie: "coolstuff" show up in this section "coolstuff" when you goto the url example.com/users/profile.php?id=3&section=coolstuff

    I hope that sums it up a bit.

  • #11
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DJCMBear View Post
    The user can make a page and put any text on it they want and others can goto it and see that text like lets say i made a page and called it hello world and wrote hello there world, if a user goes to profile.php?id=123&section=hello_world they could then see the text hello there world?
    exactly

  • #12
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Sorry if I have this wrong "again" but is it going to be a comment thing so if someone like you said makes a page called coolstuff then someone posts a comment you want it to show up on that page?

    or

    Do you mean if a user makes two sections called coolstuff then both sections get merged and both pages content gets put onto one page?
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #13
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DJCMBear View Post
    Sorry if I have this wrong "again" but is it going to be a comment thing so if someone like you said makes a page called coolstuff then someone posts a comment you want it to show up on that page?

    or

    Do you mean if a user makes two sections called coolstuff then both sections get merged and both pages content gets put onto one page?
    ok lets say the user wants to make a list of links they like.

    if they submit 3 different links in 3 different form submissions then that would be 3 new rows in the db. each link gets sent there in the table 'posts' in the column content. along with the content will be 3 other columns. "user_id, post_id, and section. I want it so that whatever they post in the one particular section "coolstuff" will only show in "coolstuff". does that help?

  • #14
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    So a mysql table looking like this.
    Code:
    | post_id | user_id |  title  |    content   |
    |    1    |    1    |  hello  |  Hello There |
    |    2    |    1    |  dude   |  Yo Dude     |
    |    3    |    2    |  hello  |  Hello There |
    Would look like this in links and page content.

    > row 1
    >> URL = example.com/users/profile.php?id=1&section=hello
    >> CONTENT = Hello There
    > row 2
    >> URL = example.com/users/profile.php?id=1&section=dude
    >> CONTENT = Yo Dude
    > row 3
    >> URL = example.com/users/profile.php?id=2&section=hello
    >> CONTENT = Hello There
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #15
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DJCMBear View Post
    So a mysql table looking like this.
    Code:
    | post_id | user_id |  title  |    content   |
    |    1    |    1    |  hello  |  Hello There |
    |    2    |    1    |  dude   |  Yo Dude     |
    |    3    |    2    |  hello  |  Hello There |
    Would look like this in links and page content.

    > row 1
    >> URL = example.com/users/profile.php?id=1&section=hello
    >> CONTENT = Hello There
    > row 2
    >> URL = example.com/users/profile.php?id=1&section=dude
    >> CONTENT = Yo Dude
    > row 3
    >> URL = example.com/users/profile.php?id=2&section=hello
    >> CONTENT = Hello There
    yes that is correct


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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