开发者

Fetch database information on a new page without using new documents

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开发者_StackOverflow中文版 process, but I'm so new to SQL and PHP coding, so go easy on me, heh.

Thanks!


<?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.


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.


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

Fetch database information on a new page without using new documents

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜