homepage Welcome to WebmasterWorld Guest from 54.167.10.244
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Order and Match
Do not envision "how to"
henry0




msg:4279691
 4:32 pm on Mar 10, 2011 (gmt 0)

I cannot come with a concept
Case:
Table with many rows, among fields are A, B, C,
each are int and contain a value from 1 to 5
example id 333 when ordered by int value comes with a result aqual at B, C, A
and here is my quandary how could I match/select all rows where the same result B, C, A as id 333 exists?

I mean doing it in a consise way and not resource "gobling".

thanks

 

henry0




msg:4279807
 6:46 pm on Mar 10, 2011 (gmt 0)

This an "ugly" and not clever nested query
so how avoiding it?

$result = $db->query("
select
a, b, c, username from my_table
where id='333'
");
while ($row=$db->fetch_array($result) )
{
$u_name=$row['username'];
$a=$row['a'];
$b=$row['b'];
$c=$row['c'];

$result2 = $db->query("
select
a, b, c, username from my_table
where username !='$u_name' AND a ='$a' AND b='$b' AND c='$c'
");
while ($row=$db->fetch_array($result2) )
{
$username=$row['username'];
echo"UN: $username";
}
}
<edit>Typo</edit>

henry0




msg:4280181
 1:38 pm on Mar 11, 2011 (gmt 0)

Mods: Since no one had a shot at it
please, move this thread to PHP forum
Perhaps, I should have been there instead of DB forum
thanks

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved