Solved

Simple PHP echo statement from MySQL query

Posted on 2008-06-15
2
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 21789436
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
ID: 21789470
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

749 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