• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
join problem..?

hi all,
i have 2 tables the 1st has names
the second has the values

i made join between 2 tables to get names and values
and i got result something like that

ahmed 1
ahmed 2
ahmed 3

and i want the result to be


how can i get this result???

You want fields from different columns in one column? This doesn't make sense... use php to achieve this.

thanks sl3dg3hamm3r for ur concern
no i doesn't mean that.i mean

NAME Value

ahmed 1

That's the nature of joins: You might end up with redundant data like in 'Name', in your case. A result from a db-query is always a flat table (except deletes, updates) and not any kind of a tree consisting of nodes and leaves.

you mean that i never echo this result with any possible way??

Err sure it is, that's why I said 'Use php' to achieve what you want. You will need to iterate over your result-set. If 'Name' was echoed and didn't change since last iteration, don't echo it anymore.

Any suggestions to do that...?coz i did my best but i couldn't reach my target result

thanks in advance

[quote author="amira_fcis" date="1258553511"]coz i did my best but i couldn't reach my target result[/quote]

And what did you do until now?

$tmpName = "";
foreach ($query->result() as $row)
  if ($tmpName != $row->Name) {
    echo $row->Name . " " . $row->Value;
    $tmpName = $row->Name;
  } else
    echo $row->Value;
This is some untested code. It implies that you have 'Name' and 'Value' in your result-set.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.