adam291086 Posted October 11, 2007 Share Posted October 11, 2007 I have a simple query that selects everything from a database and limits the results to one row ordered by desc. The code does work. The next step is to search the query result to see is if a certain feild has a result. I'm not sure how to do this. Any pointers are appreciated. <?php Include("config.php"); $con; if (!$con) { die('Could not connect: ' . mysql_error()); } $result = mysql_query("SELECT * FROM photos ORDER BY photo_id DESC LIMIT 1"); while($row = mysql_fetch_array($result)) { echo $row['photo_id']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72784-solved-searching-a-query-result/ Share on other sites More sharing options...
trq Posted October 11, 2007 Share Posted October 11, 2007 The next step is to search the query result to see is if a certain feild has a result. You shouldn't search through the result, but write your query in such a way to only retrieve the data you need. eg; SELECT * FROM foo WHERE bar = 'val'; What field do you want to check and what value do you want it checked for? Quote Link to comment https://forums.phpfreaks.com/topic/72784-solved-searching-a-query-result/#findComment-367063 Share on other sites More sharing options...
richardw Posted October 11, 2007 Share Posted October 11, 2007 One item that I use as part of a select that checks a specific field value is "metaphone". Quote Link to comment https://forums.phpfreaks.com/topic/72784-solved-searching-a-query-result/#findComment-367064 Share on other sites More sharing options...
adam291086 Posted October 11, 2007 Author Share Posted October 11, 2007 Basically what i am trying to do is search the database table and return the highest photo_id number. This equals the photo just uploaded. Then i want to check the photo_location and ensure the feild isn't empty. If it is empty then an error message is display else display photo uploaded ok. Quote Link to comment https://forums.phpfreaks.com/topic/72784-solved-searching-a-query-result/#findComment-367068 Share on other sites More sharing options...
richardw Posted October 11, 2007 Share Posted October 11, 2007 SELECT max(photo_id) as lastid FROM photos WHERE photo_filename <>''; Or did you want to grab the filename and check to see if it was uploaded and then either display or show error? Quote Link to comment https://forums.phpfreaks.com/topic/72784-solved-searching-a-query-result/#findComment-367128 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.