Jump to content

Database setup for eventual page linking


rawky1976

Recommended Posts

Hello

I posted this in another forum on this site earlier today but got no replies. I hope this is a better place to post!!!

I'm building a doument management site. Supposing I have a MySQL table with fields for document name and document description. An upload page copies the file via an upload script and file form control to a folder on the webserver (IIS).

An SQL Insert command enters into the table above whatever name and description the user has given. Next a search results page displays information from the table in a dynamic repeating table. In this table I want the doument name entry to be a link to the document itself.

Currently the user must enter the actual document name, including its file extension or the link will not function properly.

Is there a better way to go about all this? Maybe use the file upload form control, can you extract properties of the document. So the name the user enters doesn't have to be the actual file name but the link will still work?

Thanks, Mark
Link to comment
https://forums.phpfreaks.com/topic/35891-database-setup-for-eventual-page-linking/
Share on other sites

You'll need at least three fields in your database. Name, Description and Path. The Path will hold the actual path to the file. Then you could simply run a query something like.....

[code]
<?php
  // connect to db.
  $sql = "SELECT fname,fdesc,fpath FROM files;";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      while ($row = mysql_fetch_assoc($result)) {
        echo "<a href='{$row['fpath']}'>{$row['fname']}</a>. {$row['fdesc']}<br />";
      }
    }
  }
?>
[/code]
So how do I create the entry that will popultate the path field in the db? It will be something like: -

http://localhost/<site folder>/ What goes here? Is it the fileupload controls contents?

If you use the filename field that will just enter what the user calls the file in the form. As it's going to be a link then I need the actual filename including extension dont I?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.