Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Aug 2005
    Posts
    9
    Member #
    11017
    Hi,
    I have studied PHP in the past but it appears that I have been using it in a static sense, i.e. not updating web pages.

    I'm currently working on my University project and I need to update some pages dynamically. It would be easier to understand if you take a look at my website first...

    http://helios.hud.ac.uk/c0359743/project

    The only link that works so far is "Processors" and when this is clicked it takes you to the page "cpu.php", this is achieved using a href. On this page I would like it so that when the user clicks on AMD or Intel the page is updated dynamically by accessing a mySQL database and grabs information from within it. Obvioulsly this process would need to be repeated as more options would become available. I just need setting off on the right foot. I'm sure something would been to be added to the AMD and Intel text so that it is a link and the php can use it to run a query, I'm just not sure how/what.

    I haven't been able to find any good tutorials on this so far (not even the sites listed on the sticky on this forum) so if anyone knows of one it would be much appreciated.

    I have included all my files that I am using so far, nothing has been specified in the mySQL database as of yet so feel free to leave an example of what could be inserted.
    Attachment 2370

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    So, the links on the left have to request the relevant data, yes?

    Lets assume your mysql table is something like
    Code:
    id (int)
    data_title (varchar 50)
    content (text)
    
     - An example row would look like..
    id    title            content
    3    Processors   AMD Processors
    So to extract that particular row, we could use the id of that row.

    So, our link would look like
    HTML Code:
    <a href="page.php?id=3" title="title">link text</a>
    And then on page.php you extract the row which matches the value of $_GET['id']. ($_GET is a superglobal which you use to get values passed via the addressbar.

    PHP Code:
    $id $_GET['id'];
    if(!
    is_numeric($id))
      exit;

    mysql_query("SELECT title, content FROM table_name WHERE id = $id") or die("Error in select query: " mysql_error()); 

  4. #3
    Junior Member
    Join Date
    Aug 2005
    Posts
    9
    Member #
    11017
    Thanks, that was what I was after.... can't believe how simple it is ... would have never been able to work it out though.

    My thanks again

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Hey I was kinda bored so I wrote a small script for you. You dont have to use it, but the source is there if you get stuck.

    index.php has the links to getdata.php
    getdata.php uses the value passed via the querystring to select the appropiate row
    getdata.php also echo's the values out.

    create_table.txt has the code to paste into phpMyAdmin
    insert_rows.txt inserts 2 dummy rows for you to play with.

    And that should be you, a demo is at: http://bfsog.co.uk/testing/mike

    Good luck. Holla if you need help


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:26 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com