Results 1 to 9 of 9

 

Thread: New To Database Sql, Help Required Pease

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Mar 2009
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post


    Hi there, wonder if anyone can help me please.

    Im creating a database driven site, understand how to create, select and place database info into a website where i need it etc.

    What I dont get is how to make a database attached to a permalink/url. So, i have one Mysql connect code in a header and, depending what link has been clicked, it connects to a certain database and displays that information.

    I Hope this makes sense and someone out there can help, thanks!

  2. #2
    nick-harper's Avatar
    Registered User

    Status
    Online
    Join Date
    Feb 2011
    Posts
    91
    Thanks
    0
    Thanked 4 Times in 4 Posts
    I am not too sure what you mean.

    So for example:

    If somebody clicked on a domain.com/sitea it would use database a but if they used domain.com/siteb ?

    You could use an if statement in PHP and either link it to the url or url variables.

  3. #3
    Registered User

    Status
    Offline
    Join Date
    Mar 2009
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Kind of, but what im thinking of is i want one page which pulls in all the data required to build it, but wht data is pulled in depends on what link has been clicked. So, for example, i have an index page with a monkey link on it, if a user clicks on it then a new page is created from the database.

  4. #4
    paulb567's Avatar
    Registered User

    Status
    Offline
    Join Date
    Dec 2006
    Posts
    169
    Thanks
    7
    Thanked 22 Times in 20 Posts
    You'll query the database based upon values from the the request whether that be the page name/url or request parameters.

    You'll use the results from the database query (or queries) to build the response.

    Google php mysql example and you'll find 1000s of examples to get you started.
    Nothing to see here

  5. The Following 2 Users Say Thank You to paulb567 For This Useful Post:

    crumblepie1 (01-07-11)

  6. #5
    nick-harper's Avatar
    Registered User

    Status
    Online
    Join Date
    Feb 2011
    Posts
    91
    Thanks
    0
    Thanked 4 Times in 4 Posts
    OK so you want to make a new page based on the link?

    So if you had a link for example domain.com/monkey-link/

  7. The Following User Says Thank You to nick-harper For This Useful Post:

    crumblepie1 (01-07-11)

  8. #6
    Registered User

    Status
    Offline
    Join Date
    Mar 2009
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Hi,

    Thanks for the help, i think im getting there now, but there must be a problem with my code somewhere:

    My link says: http://www.sitename.com/whatever.php?link=blahblah

    And i put the following code in the header :

    <?php echo $_GET["link"];

    mysql_connect("localhost", "name", "password") or die(mysql_error());
    mysql_select_db("databasename") or die(mysql_error());

    $link = $_GET['link'];
    $row = mysql_query("SELECT * FROM $link"
    or die(mysql_error());?>

    For some reason i keep getting a syntax error, unexpected ";" on the last line, but even if i remove this i still get it, any ideas where im going wrong?

  9. #7
    Registered User

    Status
    Offline
    Join Date
    Mar 2009
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Err, scratch that, ive finally worked everything out, appreciate all the help though

  10. #8
    Registered User

    Status
    Offline
    Join Date
    Mar 2007
    Posts
    68
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Use WordPress!!! and use custom pages (no need to do a db)

  11. #9
    Registered User

    Status
    Offline
    Join Date
    Mar 2011
    Posts
    59
    Thanks
    0
    Thanked 1 Time in 1 Post
    You need a database driven site with URL re-writing...

    For example... using .htaccess re-writes you could have;

    mysite.com/fruit/bananas.html <--which is displayed to the user but shows the content from;
    mysite.com/products.php?productID=1234

    Your SQL code then takes the productID $productID = $_GET['productID'];

    And asks the database for the appropriate info

    SELECT * FROM mytable WHERE id = $id

    and you go from there



Thread Information

Users Browsing this Thread

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

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
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2