Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Simple PHP echo statement from MySQL query

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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.
Suggested Courses

618 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