10-24-2007, 04:00 PM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Sep 2007
Location: Rochester, NY
Posts: 6
Thanks: 1
|
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!
|
|
|
|