开发者

php mysql - document retrieveal and display

开发者 https://www.devze.com 2023-01-23 12:58 出处:网络
I built a document upload admin screen, where my client can browse and upload pdf documents to a mysql dbase.

I built a document upload admin screen, where my client can browse and upload pdf documents to a mysql dbase.

I have two separate tables for the Agendas, and one for Minutes. both have separate table names "upload" and "upload_mins".

on the index.php page, I have the page fetch each row of the database, and display all of the valid documents on a "download" page.

I have come a across a problem.

Each dbase is set to increment ID. now that there is two databases, they are coming to开发者_开发技巧 utilize the same ID.

so I am pulling from the Agenda table:

http://www.example.com/clerk.php?ID=77

and I am pulling from the Minutes table also:

http://www.example.com/clerk.php?ID=77

and they happen to have the same increment ID.

Is there some way to avoid this? Can I add a field parameter to the minutes to make sure that they don't have the same URL when pulling documents?

Create a integer field, or txt field?

i.e. http://www.example.com/clerk.php?ID=77&min=yes


If these are just documents, you could store them in a single table but have a column called type that differentiates between minutes and agendas. That way, IDs will be unique.

You could also extend the types column be a foreign key to a types table, so you can extend it to include additional document types such as spreadsheets in the future easily.

This would also aid the front-end display, as you would only need one query to fetch the documents within a batch or timeframe, but add them to differing arrays. For example:

// get the last 20 uploaded documents
$sql = "SELECT * FROM documents ORDER BY created DESC LIMIT 0,20";
$res = mysql_query($sql);
while ($doc = mysql_fetch_object($res)) {
    $type = $doc->type;
    if (!isset($docs[$type]) || !is_array($docs[$type])) {
        $docs[$type] = array();
    }
    $docs[$type][] = $doc;
}

// loop over agendas
foreach ($docs['agendas'] as $agenda) {
    echo '<a href="download.php?id=' . $agenda->id . '">' . $agenda->title . '</a>';
}

// loop over minutes
foreach ($docs['minutes'] as $minutes) {
    echo '<a href="download.php?id=' . $minutes->id . '">' . $minutes->title . '</a>';
}

...


You say that the problem you are having is with URLs being duplicated. You have 2 different options to solve that.

The first is to create an identifier that tells you which table you want. You could have agenda.php and minutes.php, or you could have clerk.php?ID=77&type=1 and clerk.php?ID=77&type=2.

This will allow you to know which table you are referencing. This is also the approach I would recommend. There is no reason to avoid duplicate keys in different tables as long as you have a way of knowing which table you need.

The second option is to put all your records into a single table. You can then add a type column that specifies what type of document it is. You can then leave your clerk.php file alone, but need to change the upload page to populate the type column.

If you are just storing PDFs in the database, you shouldn't need anything in this table except id, type, and the document itself.

0

精彩评论

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