Solved

Simple PHP echo statement from MySQL query

Posted on 2008-06-15
2
357 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

691 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