jeff5656 Posted September 30, 2009 Share Posted September 30, 2009 I want to select a record and use WHERE to ensure that the record is unique. Since I know it will be unique, is there a simpler way to code it withut usuang a while to loop through the whole database? I have this so far. The next line would be a while loop, but if i echo $result is gives me "Resource ID#3" $query = "SELECT * FROM website WHERE title = 'main-topleft' "; $results = mysql_query ($query); echo "results is".$results;?> Quote Link to comment Share on other sites More sharing options...
Jibberish Posted September 30, 2009 Share Posted September 30, 2009 Yes just do $results = mysql_fetch_assoc($resultSet); echo $result['an_index']; that will select the first result in the result set, prob best to check there is one first with mysql_num_rows() just to be safe though. Quote Link to comment Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 EDIT: Beaten to the punch... If you know it will be unique, use LIMIT 1, so that MySQL doesn't keep looking once it's found the answer. In order to access the date you will need to use mysql_fetch_assoc or mysql_fetch_array (or similar). <?php $query = "SELECT * FROM website WHERE title = 'main-topleft' LIMIT 1"; $results = mysql_query ($query); $row = mysql_fetch_assoc($results); echo $row['field_name_here']; ?> Quote Link to comment Share on other sites More sharing options...
jeff5656 Posted September 30, 2009 Author Share Posted September 30, 2009 Thanks guys! Quote Link to comment 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.