Forum Moderators: coopster

Message Too Old, No Replies

Sorting, replacing and hiding

         

Awful newbie

11:30 am on Jun 1, 2007 (gmt 0)

10+ Year Member



This script makes it possible to list data and blobs from mysql. I wonder:
1. How can I replace the listed mime-types with icons?
2. How can I make the user to choose wheter to list ASC or DESC from the different columns?
3. How can I hide the blobID with, for example, #?

I am still a newbie so I need teaspoons... Here is the script:

<?php

include('db_connection.php');

$sConn = mysql_connect($dbServer, $dbUser, $dbPass)
or die("Couldn't connect to database server");

$dConn = mysql_select_db($file_database, $sConn)
or die("Couldn't connect to database $dbDatabase");

$dbQuery = "SELECT blobId, blobTitle, blobType ";
$dbQuery .= "FROM myBlobs WHERE blob_cat=3 ";
$dbQuery .= "ORDER BY blobTitle ASC";
$result = mysql_query($dbQuery) or die("Sorry, halted");
?>

<table border="1" width="100%">
<tr>
<td width="34%" bgcolor="#FF9900"><b>Description</b></td>
<td width="33%" bgcolor="#FF9900"><b>Type</b></td>
<td width="33%" bgcolor="#FF9900"><b>File</b></td>
</tr>

<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td width="34%"><?php echo $row["blobTitle"];?></td>
<td width="33%"><?php echo $row["blobType"];?></td>
<td width="33%"><a href="download.php?fileId=<?php echo $row["blobId"];?>">Download file</a></font>
</td>
</tr>
<?php
}
echo "</table>";
?>

Scally_Ally

1:44 pm on Jun 1, 2007 (gmt 0)

10+ Year Member



as with anything, there are alot of ways to achieve the same result, here is 1 way.

1. have a switch statement to recognise what the mime type is, then based on that result show a different image.


switch ($row["blobType"]){
case "application/zip":
$myImage = "zip.gif";
break;
case "image/jpg":
$myImage = "jpeg.gif";
break;
}
<img src="<?php echo $myImage;?>">

2. have the user choose from a drop down what order they want, and then rewrite you SQL query accordingly.


$order = $_POST["order"];
$query = "SELECT * FROM myTable ORDER BY row1 $order";

3. You cant really hide the blobID, if you want to use it on the querystring it has to be present. You could maybe encrypt it and then decrypt it when you want to use it maybe..

Ally

[edited by: Scally_Ally at 1:44 pm (utc) on June 1, 2007]