?
Solved

Simple PHP echo statement from MySQL query

Posted on 2008-06-15
2
Medium Priority
?
359 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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …
Suggested Courses

764 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