mike6256 Posted February 24, 2009 Share Posted February 24, 2009 Hi all I need some help with a code that will display specific info and image from my DB. The code I have will display all DB info with a download link for each result. This would work if it only displayed a single search result. Any help would be appreciated. the code follows: <?php # Connect to the database $dbLink = mysqli_connect("127.0.0.1", "user", "pwd", "dbName"); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } # Query for a list of all existing files $result = mysqli_query($dbLink, "SELECT FileID, FileName, FileMime, FileSize, Created FROM FileStorage"); # Check if it was successfull if($result) { # Make sure there are some files in there if(mysqli_num_rows($result) == 0) { echo "<p>There are no files in the database</p>"; } else { # Print the top of a table echo "<table width='100%'><tr>"; echo "<td><b>Name</b></td>"; echo "<td><b>Mime</b></td>"; echo "<td><b>Size (bytes)</b></td>"; echo "<td><b>Created</b></td>"; echo "<td><b> </b></td>"; echo "</tr>"; # Print each file while($row = mysqli_fetch_assoc($result)) { # Print file info echo "<tr><td>". $row['FileName']. "</td>"; echo "<td>". $row['FileMime']. "</td>"; echo "<td>". $row['FileSize']. "</td>"; echo "<td>". $row['Created']. "</td>"; # Print download link echo "<td><a href='get_file.php?id=". $row['FileID'] ."'>Download</a></td>"; echo "</tr>"; } # Close table echo "</table>"; } # Free the result mysqli_free_result($result); } else { echo "Error! SQL query failed:"; echo "<pre>". $dbLink->error ."</pre>"; } # Close the mysql connection mysqli_close($dbLink); ?> Link to comment https://forums.phpfreaks.com/topic/146675-displaying-image/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 24, 2009 Share Posted February 24, 2009 What exactly is the problem? Link to comment https://forums.phpfreaks.com/topic/146675-displaying-image/#findComment-770039 Share on other sites More sharing options...
mike6256 Posted February 24, 2009 Author Share Posted February 24, 2009 The main problem is the code will display all data in DB. I would like it to display the result of a single search. Link to comment https://forums.phpfreaks.com/topic/146675-displaying-image/#findComment-770043 Share on other sites More sharing options...
PFMaBiSmAd Posted February 24, 2009 Share Posted February 24, 2009 http://w3schools.com/sql/sql_where.asp Link to comment https://forums.phpfreaks.com/topic/146675-displaying-image/#findComment-770044 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.