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 9 of 9
  1. #1
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Using parameters and query

    Hej!

    I have many pictures from a library to books so i need to create a query in PHP like this:
    Code:
    mybooks.php?showbook=1
    Please help!
    Exp:
    PHP
    .NET

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Not sure what you asking. It sounds like you want to use the the showbook value inside of a mysql query. While I won't write the whole thing for you, this should get your started.
    PHP Code:
    $showbook ='';
    if(isset(
    $_GET['showbook']) && $_GET['showbook'] != '')
    {
    $showbook $_GET['showbook'];
    }
    $sql "SELECT * FROM tablename WHERE bookid = $showbook";
    $query mysql_query($sql) or die('The mysql error is :' mysql_error() .'<br>The query is: ' $sql); 
    After the query runs you can use mysql_fetch_array to get what you want displayed. Be sure to change tablename to the correct name of the table in your database.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts

    I mean the query, see this

    I mean that if i have a database ike this:
    Code:
       ID      Picture             Description
        1     some1.jpg        Its a new book
        2     some2.jpg        Its a future book
        3     some3.jpg        Its a old book
        4     some4.jpg        Its a history book
    Then when i type in the adress bar: showbook.php?id=1
    it will show the picture some1.jpg and the description of some1.jpg
    Exp:
    PHP
    .NET

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Right. What kind of database do you have? If its mysql then I gave you what you need to do it. I even told you what function to use to get the correct data.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Right. What kind of database do you have? If its mysql then I gave you what you need to do it. I even told you what function to use to get the correct data.
    Ok, thanks but can you just give me the sql database name och the table name because i can't read the SQL
    Exp:
    PHP
    .NET

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I don't know that information. You should have set this information when you setup your database.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    I don't know that information. You should have set this information when you setup your database.
    Ok, thank you!
    Exp:
    PHP
    .NET

  • #8
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I get this error when i try:
    Code:
    The mysql error is :Access denied for user 'vhostswww'@'localhost' (using password: NO)
    The query is: SELECT * FROM table2 WHERE bookid =
    Exp:
    PHP
    .NET

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Did you connect to the database? You need a username and password to connect to the database. You can use mysql_connect(). Then you will need to use mysql_select_db() to select the correct database.
    ||||If you are getting paid to do a job, don't ask for help on 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
    •