How do I retrieve only one row of database info? here's what I have so
far
<?php
$db_host = "localhost";
$db_user = "username";
$db_pwd = "password";
$db_name = "dbname";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>
<table>
<?php
$sql = "SELECT * FROM colors";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['favoriteColor']."</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
Any help would be great. Thanks again! 6 9352
On Wed, 03 Oct 2007 16:41:08 +0200, Lamer <Ga******@gmail.comwrote:
How do I retrieve only one row of database info? here's what I have so
far
$sql = "SELECT * FROM colors";
http://dev.mysql.com/doc/refman/4.1/en/select.html
Check out the 'LIMIT' clause.
--
Rik Wasmus
On 3 oct, 11:41, Lamer <Galat...@gmail.comwrote:
How do I retrieve only one row of database info? here's what I have so
far
<?php
$db_host = "localhost";
$db_user = "username";
$db_pwd = "password";
$db_name = "dbname";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>
<table>
<?php
$sql = "SELECT * FROM colors";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['favoriteColor']."</td>";
echo "</tr>";}
?>
</table>
</body>
</html>
Any help would be great. Thanks again!
Hello,
well i didn't understand your question very well, but i suppose that
you want to obtain just one row from the table "colors".
to do that you need to add a "where" clause in your mysql query, for
instance "select * from colors where idColor=1"
or you can remove the while and keep only the line $row =
mysql_fetch_array($query); but is not the best way.
bye
Claudio
In article <11*********************@o80g2000hse.googlegroups. com>,
Claudio Corlatti <co******@gmail.comwrote:
>well i didn't understand your question very well, but i suppose that you want to obtain just one row from the table "colors".
to do that you need to add a "where" clause in your mysql query, for instance "select * from colors where idColor=1"
That will work, but a LIMIT should also be specified for efficiency.
The query "SELECT * FROM MyColorTable WHERE ColorID=26 LIMIT 1" will
cause MySQL to stop searching the table as soon as one row is found.
Otherwise it will keep searching for other rows with ColorID=26.
-A
"axlq" <ax**@spamcop.netwrote in message
news:fe**********@blue.rahul.net...
In article <11*********************@o80g2000hse.googlegroups. com>,
Claudio Corlatti <co******@gmail.comwrote:
>>well i didn't understand your question very well, but i suppose that you want to obtain just one row from the table "colors".
to do that you need to add a "where" clause in your mysql query, for instance "select * from colors where idColor=1"
That will work, but a LIMIT should also be specified for efficiency.
The query "SELECT * FROM MyColorTable WHERE ColorID=26 LIMIT 1" will
cause MySQL to stop searching the table as soon as one row is found.
Otherwise it will keep searching for other rows with ColorID=26.
-A
WHY does the OP wand to stop at one? Is this simply check for the
existinance of some value in a particular field/ If that is so, why not use
the COUNT operator in the sql call?
Shelly
"Gary L. Burnore" <gb******@databasix.comwrote in message
news:fe**********@blackhelicopter.databasix.com...
You sure quoted a lot
as did you :-)
to say "I agree" :)
On 3 oct, 21:09, a...@spamcop.net (axlq) wrote:
In article <1191424134.543150.96...@o80g2000hse.googlegroups. com>,
Claudio Corlatti <corla...@gmail.comwrote:
well i didn't understand your question very well, but i suppose that
you want to obtain just one row from the table "colors".
to do that you need to add a "where" clause in your mysql query, for
instance "select * from colors where idColor=1"
That will work, but a LIMIT should also be specified for efficiency.
The query "SELECT * FROM MyColorTable WHERE ColorID=26 LIMIT 1" will
cause MySQL to stop searching the table as soon as one row is found.
Otherwise it will keep searching for other rows with ColorID=26.
-A
yes, you are right the limit function is the best option in this case. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bob Kaku |
last post by:
I'm trying to retrieve a text value from a MySQL database, put it into
an updateable form, allow edits, and send back the edited text back
into the MySQL database. I've been able to successfully...
|
by: Andy Jackman |
last post by:
Hi,
I'm new to mySql. I've got a table with an integer field defined like
this:
l_start_wait int(9) not null
I inserted a value into the table using mysql command line client with:
Insert into...
|
by: Robert Kattke |
last post by:
Subject: Can you retrieve/restore a MySQL user Password ?
I'm working on my own, local WXP, MySQL, version: 3.23.38-nt
and I have the "root" password, and normally use the root account.
I have...
|
by: Daniel Tonks |
last post by:
First, please excuse the fact that I'm a complete MySQL newbie.
My site used forum software that I wrote myself (in Perl) which, up until
now, has used flat files. This worked fine, however...
|
by: Roy Gourgi |
last post by:
Hi,
I am used to working in Visual FoxPro and I would like to be able to create
a database and store and retrieve information from it. What is the simplest
way to do it and what should I be...
|
by: DaveF |
last post by:
How can I retrieve display_names
Dim custDS As DataSet = New DataSet
Dim mySQL, mySQL2, mySQL3 As String
|
by: no.mail.pls |
last post by:
Hiya,
How do i retreive fields with similar values from 2 tables?
I tried to use
(1) "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like
'%p.name%'";
but it retrieves nothing at...
|
by: JM |
last post by:
Before storing information from a form in database I perform follwing
operations on it :
$path =
mysql_real_escape_string(strip_tags(trim(urldecode($_POST))));
$summary =...
|
by: chumlyumly |
last post by:
Hi -
I'm working with
PHP5
MySQL
Mac OSX
I've developed two pages where a user can input his/her info, which goes to a MySQL database. The first page is supposed to pass the newly created...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |