CodeIgniter Forums
join problem..? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: join problem..? (/thread-24709.html)



join problem..? - El Forum - 11-17-2009

[eluser]amira_fcis[/eluser]
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

ahmed
1
2
3

how can i get this result???


join problem..? - El Forum - 11-17-2009

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


join problem..? - El Forum - 11-17-2009

[eluser]amira_fcis[/eluser]
thanks sl3dg3hamm3r for ur concern
no i doesn't mean that.i mean


NAME Value

ahmed 1
2
3


join problem..? - El Forum - 11-17-2009

[eluser]sl3dg3hamm3r[/eluser]
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.


join problem..? - El Forum - 11-17-2009

[eluser]amira_fcis[/eluser]
you mean that i never echo this result with any possible way??


join problem..? - El Forum - 11-17-2009

[eluser]sl3dg3hamm3r[/eluser]
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.


join problem..? - El Forum - 11-18-2009

[eluser]amira_fcis[/eluser]
Any suggestions to do that...?coz i did my best but i couldn't reach my target result

thanks in advance


join problem..? - El Forum - 11-18-2009

[eluser]sl3dg3hamm3r[/eluser]
[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?

Code:
$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.