Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to grab rows that have a certain category.
Old 09-22-2008, 11:58 AM How to grab rows that have a certain category.
Colin's Avatar
Average Talker

Posts: 27
Name: Colin Smiley
Trades: 0
Hey, I am working on a tutorial system for my site. and right now I have my MySQL Database set up and the pages for it mostly setup (On WAMP).

I have it so it will support categories, For example.Each tutorial gets a field for category, I want to know how to echo just the tutorials with their category set to "1" On a page, So if i want a page for just Photoshop tutorials I get it, And if I want one for just CSS Tutorials I get it.

Can anyone help? Thanks.
Colin is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-22-2008, 12:35 PM Re: How to grab rows that have a certain category.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
SELECT fieldlist FROM table WHERE category_field = number_to_filter_by
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-22-2008, 01:37 PM Re: How to grab rows that have a certain category.
admsys's Avatar
Novice Talker

Posts: 5
Trades: 0
PHP Code:
$res mysql_query("SELECT * FROM table where categories='1' limit 1"
or die(
mysql_error());  

while(
$row mysql_fetch_array$res )) {
echo 
$row['id'];
echo 
"<br>"
echo 
$row['categories'];
echo 
"<br>"

__________________
Looking for cheap&fast hosting ?

Please login or register to view this content. Registration is FREE
- $2.00/month, Quota : 200 GB, Bandwidth : Unmetered
admsys is offline
Reply With Quote
View Public Profile
 
Old 09-22-2008, 02:25 PM Re: How to grab rows that have a certain category.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You should NOT use SELECT * in REAL queries
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-23-2008, 03:43 AM Re: How to grab rows that have a certain category.
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Chris, what is the real slowdown of "select *" compared to "select id, name, otherstuff"? I suspect that it is like saving on matches, especially when using joins or selecting from tables with high number of rows.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 09-23-2008, 05:09 AM Re: How to grab rows that have a certain category.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
At the very least it forces an extra pass through the database(s) to get the column names.
But the biggest one is that it will return every column and the data which can be a huge memory hog especially if you only need one or two columns.

Take the query above for example;
returns ALL columns and only uses two of them. Maybe not an issue by itself or for one or two queries several minutes apart.
BUT what if the table has 50 fields? That could be a huge chunk of space that the OS has to reserve in memory as a array, when in reality in may only need 10 bytes per record.
Then scale that up to several queries a minute with a million row table.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to How to grab rows that have a certain category.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17052 seconds with 12 queries