Jump to content

[SOLVED] selecting one record without using while?


jeff5656

Recommended Posts

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;?>

Link to comment
Share on other sites

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'];
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.