CodeIgniter Forums

Full Version: join problem..?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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???

El Forum

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

El Forum

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


NAME Value

ahmed 1
2
3

El Forum

[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.

El Forum

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

El Forum

[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.

El Forum

[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

El Forum

[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.