TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 10-24-2007, 03:00 PM   #1 (permalink)
The Wanderer
 
Acrylic's Avatar
 
Join Date: Sep 2007
Location: Rochester, NY
Posts: 6
Thanks: 1
Acrylic is on a distinguished road
Default MySQL - Is there a better way to SELECT

I am fairly new to the whole PHP MySQL stuff, I can make it work but don't know all the optimizations and such. I know very little MySQL and figured there has got to be a better way of doing this...

Currently I am doing this, each query is specific to a 'type' and each result is put into a different table.

PHP Code:
$result1 mysql_query("SELECT * FROM user_links WHERE type='0' AND user_id='".$g_id."' ORDER BY id");
$result2 mysql_query("SELECT * FROM user_links WHERE type='1' AND user_id='".$g_id."' ORDER BY id");
$result3 mysql_query("SELECT * FROM user_links WHERE type='2' AND user_id='".$g_id."' ORDER BY id");
$result4 mysql_query("SELECT * FROM user_links WHERE type='3' AND user_id='".$g_id."' ORDER BY id");
$result5 mysql_query("SELECT * FROM user_links WHERE type='4' AND user_id='".$g_id."' ORDER BY id");
$result6 mysql_query("SELECT * FROM user_links WHERE user_id='".$g_id."'");
$num_rows6 mysql_num_rows($result6); 
so after thats done, each $result* is "echo'd" into a separate table to categorize them, $result6 and $num_rows6 is used to see if they even have any data in 'user_links' and if not then i prompt them with an add button. is there any better was instead of doing all those select statements and a better way to do what i descried with $result6?

Thanks!
Acrylic is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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


All times are GMT. The time now is 02:53 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design