tags:

views:

65

answers:

4

I'm working on a page where I've listed some entries from a database. Although, because the width of the page is too small to fit more on it (I'm one of those people that wants it to look good on all resolutions), I'm basically only going to be able to fit one row of text on the main page.

So, I've thought of one simple idea - which is to link these database entries to a new page which would contain the information about an entry. The problem is that I actually don't know how to go about doing this. What I can't figure out is how I use the PHP code to link to a new page without using any new documents, but rather just gets information from the database onto a new page. This is probably really basic stuff, but I really can't figure this out. And my explanation was probably a bit complicated.

Here is an example of what I basically want to accomplish: http://vgmdb.net/db/collection.php?do=browse&ltr=A&field=&perpage=30

They are not using new documents for every user, they are taking it from the database. Which is exactly what I want to do. Again, this is probably a really simple process, but I'm so new to SQL and PHP coding, so go easy on me, heh.

Thanks!

A: 
<?php
  // if it is a user page requested
  if ($_GET['page'] == 'user') {
    if (isset($_GET['id']) && is_numeric($_GET['id'])) {
      // db call to display user WHERE id = $_GET['id']
      $t = mysql_fetch_assoc( SELECT_QUERY );
      echo '<h1>' . $t['title'] . '</h1>';
      echo '<p>'  . $t['text']  . '</p>';
    } else {
      echo "There isn't such a user".
    }
  } 

  // normal page logic goes here
  else {
    // list entries with links to them
    while ($t = mysql_fetch_assoc( SELECT_QUERY )) {
      echo '<a href="/index.php?page=user&amp;id='. $t['id'] .'">';
      echo $t['title'] . '</a><br />';
    }
  }
?>

And your links should look like: /index.php?page=user&id=56

Note: You can place your whole user page logic into a new file, like user.php, and include it from the index.php, if it turns out that it it a user page request.

galambalazs
I'm sorry. I think I formulated the last part a little wrong.See, what I don't get is, uhm... where I put the code for each new entry, and how I format the links to the pages.It's a little hard to explain I guess, but I hope you understand.
Nisto
i've updated a bit. I don't get what you mean formatting. Like css???
galambalazs
and you don't have to put any new code for each entry. Entries should be in the database, and so your PHP won't change at all. That's the power of using a database.
galambalazs
you have your entries table in your database right?
galambalazs
Yes, of course.
Nisto
A: 

Bump. Still need help with this!

Nisto
A: 

Nisto, it sounds like you have some PHP output issues to contend with first. But the link you included had some code in addition to just a query that allows it to be sorted alphabetically, etc.

This could help you accomplish that task:

www.datatables.net

In a nutshell, you use PHP to dynamically build a table in proper table format. Then you apply datatables via Jquery which will automatically style, sort, filter, and order the table according to the instructions you give it. That's how they get so much data into the screen and page it without reloading the page.

Good luck.

bpeterson76
A: 

Are you referring to creating pagination links? E.g.:

pagination example

If so, then try Pagination - what it is and how to do it for a good walkthrough of how to paginate database table rows using PHP.

Lauren