Solved

Simple PHP echo statement from MySQL query

Posted on 2008-06-15
2
347 Views
Last Modified: 2008-06-15
Hi there,

This a very simple question. When I retrieve query results I usually use a while statement and table to echo out results.

However in this case i just want to echo out one field.

The query:

$query99 = "SELECT AreaName FROM area WHERE AreaID= $aid";
$result99 = mysql_query ($query99);

How do I echo out the AreaName?
0
Comment
Question by:dm404
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
Comment Utility
you could still use the loop syntax, but the fastest is:
$query99 = "SELECT AreaName FROM area WHERE AreaID= $aid";
$result99 = mysql_query ($query99);
echo mysql_result($result99,0,0);

Open in new window

0
 
LVL 3

Expert Comment

by:Fapiko
Comment Utility
A simple way to do this is to use the code below. This creates an object from the result of the query. If you wanted to fetch multiple values, you could set $query99 = 'SELECT * FROM `area` WHERE AreaID = $aid"; and echo "$row->AreaName  $row->AreaID  $row->AreaLocation"; etc.


$query99 = "SELECT AreaName FROM area WHERE AreaID= $aid";

$result99 = mysql_query ($query99);

$row = mysql_fetch_object($result99);
 

echo $row->AreaName;

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now