I have two file one called show.php and one is show.tpl.

On show.php it has this code

  //-----------------------------------------
  //  Fetch Media
  //-----------------------------------------
  $db->query("SELECT files.*, categories.*, users.id, users.username FROM categories, files LEFT JOIN users ON files.mid=users.id WHERE $search_addon files.category_id=categories.category_id AND files.type != 'plug' AND $v $ss ORDER BY files.featured DESC, files.$sort LIMIT $set_limit, $per_page");
  $lists = $db->fetch_rows();
  $media_num = $db->get_num_rows();[/QUOTE]

On show.tpl it has this code

<table align="center" border="0" cellpadding="4" cellspacing="1" class="admin_table">
<tr class="main_row_color">
    <td style='width:1%;'><a href="{$siteurl}/admin.php?view=admin_media&sort=file_id"><b>ID</b></a></td>
    <td style='width:30%;' colspan="2"><a href="{$siteurl}/admin.php?view=admin_media&sort=title"><b>Title</b></a></td>
    <td style='width:20%;'><a href="{$siteurl}/admin.php?view=admin_media&sort=category_id"><b>Category</b></a></td>
    <td style='width:15%;'><a href="{$siteurl}/admin.php?view=admin_media&sort=mid"><b>Uploader</b></a></td>
    <td style='width:10%;'><b>Options</b></td>
    <td style='width:1%;'><b>Select</b></td>
</tr>

Together when loaded it shows the table below

ID      Title   Category    Uploader    Options     Select

My question is how can I get it to show artist from "files" table in my database for it to show what I want below?

ID      Title   Artist      Category    Uploader    Options     Select

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Hi Welbzobeng,
have a look at the query. After SELECT and before FROM it lists what attributes it will fetch for you. files.* means "all attributes from table files so your artist should be covered.
You didn't say what attributes your db table "files" has so I can only assume that artist name is one of them. Let's assume it's called "artist".

You only showed us a part of show.tpl that displays table headings. Adding a new heading for Artist is easy, just insert this:

<td><a href="{$siteurl}/admin.php?view=admin_media&sort=artist"><b>Artist</b></a></td>

This piece of code also adds the link for sorting. I hope that somewhere in show.php you secure values in $sort because if not you're risking a SQL injection attack.

You didn't provide PHP code that assigns result of the query to your template (if you're using Smarty then it's something like $smarty->assign('variable', $values); ) and you didn't give us the part of your template that actually shows it. You will have to edit the template part and maybe the PHP part as well.
Post them here if you need more help.

Also I wouldn't be surprised if you had a separate db table for artists and "files" only used artist.id as a foreign key. Give us more details on your db tables if you need assistance here.

This article has been dead for over six months. Start a new discussion instead.