You are here: Re: How do I simplify this SELECT query? « All PHP « IT news, forums, messages
Re: How do I simplify this SELECT query?

Posted by Surfer! on 09/28/45 11:44

In message <1144483472.431452.152910@v46g2000cwv.googlegroups.com>,
endlesstide@gmail.com writes
>$sql_query = "SELECT * FROM $table WHERE entry = 4";
>
>// now put all the data into arrays
>$dd = 0;
>while ($row = mysql_fetch_row($result)) {
> $column4[$dd] = $row[3];
>$dd++;
>
>
>I am trying to simplifly this query -- I don't want to select * from
>the table, I want to only get data from column called "column4".

SELECT column4 FROM $table WHERE entry = 4

> I
>know the next part putting into the arrays is redundent. I just want a
>single record.

If you are sure your WHERE clause will just get a single row, you can
dispense with the while construct and just use the mysql_fetch_row.
However that will generate an error if the WHERE clause picks up more
than 1 row.


> Is running a select * going to add lots of overhead to
>the server?
>

Depends on the table. If it has lots of columns and the columns are
wide then yes, it will make a difference especially if the program keeps
getting different rows.

I suggest you do some RTFM, PDQ. Lots and lots of RTFM in fact, and
that you use Google to find some basic SQL tutorials.

http://dev.mysql.com/doc/
http://dev.mysql.com/doc/refman/5.0/en/retrieving-data.html

--
Surfer!
Email to: ramwater at uk2 dot net

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация