Warptweet Posted April 2, 2007 Share Posted April 2, 2007 I use this code to select particular rows... $con = mysql_connect("localhost","warp_portal","6151851"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("warp_portal", $con); $result = mysql_query("SELECT * FROM file_manager WHERE file_type='image/x-png'"); echo "<table border=\"1\"> <tr> <th>Image</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><img src=\"" . $row['file_location'] . "\"></td>"; echo "</tr>"; } echo "</table>"; How can I make it select where rows have a column having image/x-png OR image/gif? So basically if there was 1 image with image/x-png and 1 with image/gif then with would display BOTH, because they both match the criteria. Thanks for any help -Warptweet Link to comment https://forums.phpfreaks.com/topic/45225-mysql-database-where-help/ Share on other sites More sharing options...
per1os Posted April 2, 2007 Share Posted April 2, 2007 $result = mysql_query("SELECT * FROM file_manager WHERE (file_type='image/x-png' OR file_type='image/gif')"); Simple as that, remember to use the parans. Link to comment https://forums.phpfreaks.com/topic/45225-mysql-database-where-help/#findComment-219561 Share on other sites More sharing options...
jitesh Posted April 2, 2007 Share Posted April 2, 2007 "SELECT * FROM file_manager WHERE file_type IN ('image/x-png','file_type='image/gif')"; Link to comment https://forums.phpfreaks.com/topic/45225-mysql-database-where-help/#findComment-219575 Share on other sites More sharing options...
Warptweet Posted April 2, 2007 Author Share Posted April 2, 2007 Thanks, but how would I add: AND file_author='$username'? Because I only want the member that is viewing that page to view those file rows which contain their $username that matches. Otherwise the member would be viewing images that are not uploaded by him. ANOTHER QUESTION: How would I make it display every file that is NOT image/gif or image/x-png? Link to comment https://forums.phpfreaks.com/topic/45225-mysql-database-where-help/#findComment-219590 Share on other sites More sharing options...
per1os Posted April 2, 2007 Share Posted April 2, 2007 $sql = "SELECT * FROM file_manager WHERE file_type NOT IN ('image/x-png','file_type='image/gif')"; $sql = "SELECT * FROM file_manager WHERE file_type IN ('image/x-png','file_type='image/gif') AND file_author = '$username'"; $sql = "SELECT * FROM file_manager WHERE file_type NOT IN ('image/x-png','file_type='image/gif') AND file_author = '$username'"; Should work. You may want to learn SQL man, because that is really basic basic sql. Link to comment https://forums.phpfreaks.com/topic/45225-mysql-database-where-help/#findComment-219591 Share on other sites More sharing options...
Warptweet Posted April 2, 2007 Author Share Posted April 2, 2007 Here is my code: if ($_GET['cmd'] == 'filemanager'){ if (isset($_SESSION['s_username'])) { $username = "".$_SESSION['s_username'].""; $con = mysql_connect("localhost","warp_portal","6151851"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("warp_portal", $con); $result = "SELECT * FROM file_manager WHERE file_type IN ('image/x-png','file_type='image/gif') AND file_author = '$username'"; echo "<table border=\"1\"> <tr> <th>Image</th> <th>View</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><img src=\"" . $row['file_location'] . "\" width=\"100\" height=\"100\"></td>"; echo "<td><a href=\"" . $row['file_location'] . "\">View Image</a></td>"; echo "</tr>"; } echo "</table></br></br>"; $con = mysql_connect("localhost","warp_portal","6151851"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("warp_portal", $con); $result = "SELECT * FROM file_manager WHERE file_type NOT IN ('image/x-png','file_type='image/gif') AND file_author = '$username'"; echo "<table border=\"1\"> <tr> <th>File ID</th> <th>View</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['file_id'] . "</td>"; echo "<td><a href=\"" . $row['file_location'] . "\">Download</a></td>"; echo "</tr>"; } echo "</table>"; echo "</br></br>Welcome ".$_SESSION['s_username']." to your personal File Manager, an organized way to upload your files and images to distribute them anywhere on the internet, or for Submitting Content to this website! Feel free to excercise your right to have a personal file manager as a member!</br></br><font size=\"1\">Allowed File Types: .gm6, .gm5, .gex, .gmd, .gmk, .jpg, .gml, .gif, .png, .zip, .tar, .swf, .wmv, .mid, .pdf, .psd, .txt, .rar, and .jpeg.</br>Maximum File Size: 100MB</br></font> <form enctype=\"multipart/form-data\" action=\"?cmd=procfile\" method=\"POST\"> Send this file: <input name=\"file\" type=\"file\" /><br /> <input type=\"submit\" value=\"Upload File\" /> </form>"; } } And for some reason I get this error at my tables where is has "Image" as one of it's columns: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/warp/public_html/gm/testing.php on line 380 And here is the error for the part where the table has File ID as one of it's columns: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/warp/public_html/gm/testing.php on line 405 Link to comment https://forums.phpfreaks.com/topic/45225-mysql-database-where-help/#findComment-219599 Share on other sites More sharing options...
per1os Posted April 2, 2007 Share Posted April 2, 2007 $result = "SELECT * FROM file_manager WHERE file_type IN ('image/x-png','file_type='image/gif') AND file_author = '$username'"; echo "<table border=\"1\"> <tr> <th>Image</th> <th>View</th> </tr>"; while($row = mysql_fetch_array($result)) Where are you calling mysql_query() ?? Link to comment https://forums.phpfreaks.com/topic/45225-mysql-database-where-help/#findComment-219789 Share on other sites More sharing options...
Warptweet Posted April 2, 2007 Author Share Posted April 2, 2007 $username = "".$_SESSION['s_username'].""; $con = mysql_connect("localhost","warp_portal","NOT TELLING"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("warp_portal", $con); $result = mysql_query("SELECT * FROM file_manager WHERE file_type IN ('image/x-png','file_type='image/gif') AND file_author = '$username'"); echo "<table border=\"1\"> <tr> <th>Image</th> <th>View</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><img src=\"" . $row['file_location'] . "\" width=\"100\" height=\"100\"></td>"; echo "<td><a href=\"" . $row['file_location'] . "\">View Image</a></td>"; echo "</tr>"; } echo "</table></br></br>"; $con = mysql_connect("localhost","warp_portal","NOT TELLING"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("warp_portal", $con); $result = mysql_query("SELECT * FROM file_manager WHERE file_type NOT IN ('image/x-png','file_type='image/gif') AND file_author = '$username'"); echo "<table border=\"1\"> <tr> <th>File ID</th> <th>View</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['file_id'] . "</td>"; echo "<td><a href=\"" . $row['file_location'] . "\">Download</a></td>"; echo "</tr>"; } echo "</table>"; I still get the same errors, whats wrong? It should be perfect... Link to comment https://forums.phpfreaks.com/topic/45225-mysql-database-where-help/#findComment-220011 Share on other sites More sharing options...
per1os Posted April 2, 2007 Share Posted April 2, 2007 use this //I do not know why "'file_type='image/gif')" this was used but change it to this: $result = mysql_query("SELECT * FROM file_manager WHERE file_type NOT IN ('image/x-png','image/gif') AND file_author = '$username'") or DIE(mysql_error()); If mysql is throwing an error report the error but that should fix it. Link to comment https://forums.phpfreaks.com/topic/45225-mysql-database-where-help/#findComment-220070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.