Welcome Guest, Not a member yet? Register   Sign In
problem in displaying in correct format
#1

[eluser]phpbeginner[/eluser]
I'm just started programming and having problem in displaying my result in correct format.
code from model :
Code:
function compare($val)
{
$id=$val;
$this->db->select('pf.availability AS feature');
$this->db->from('product_master pm');
$this->db->join('product_feature pf', 'pf.product_id = pm.product_id');
$this->db->where_in('pm.product_id', $id);
$this->db->where_in('Select feature_id from feature');
$query = $this->db->get() or die(mysql_error());        
return $query->result();
}
this i call through controller
Code:
$temp = array('cmp'=> $this->user_model->compare($checkbox));    
$this->load->view('compare',$temp);
All this is fine.. I wan to display the result in array all availability of one product in 1 column and 2nd product feature availability in nd column . Same as you see in mobile store website when u compare 2 cellphone.
Code:
<?php foreach($cmp as $item  ):?>
<tr></tr>
<td>&lt;?php echo $item->feature;?&gt;</td>
</tr>
&lt;?php
endforeach; ?&gt;
</table>
using this ,but everything is being displayed in same column.
please advice how to arrange in proper format.
#2

[eluser]smilie[/eluser]
Try:

Code:
&lt;?php foreach($cmp as $item  ):?&gt;
<tr>
<td>&lt;?php echo $item->feature;?&gt;</td>
</tr>
&lt;?php
endforeach; ?&gt;
</table>
#3

[eluser]phpbeginner[/eluser]
thank for reply.
but its displaying all in vertical(in same column)
I want to have a from up to down rather than left to right.
or is there any other way I can print array on view page.
what i want is
Quote: prod 1 prod2
availability availability

right now its displaying
Quote: prod1
availability of prod 1
availability of prod 2
availability of prod 3
#4

[eluser]smilie[/eluser]
Can you please post result of:

Code:
echo '<pre>'; print_r($cmp); echo '</pre>';

Cheers,
Smilie
#5

[eluser]phpbeginner[/eluser]
Code:
Array
(
    [0] => stdClass Object
        (
            [feature] => yes
        )

    [1] => stdClass Object
        (
            [feature] => no
        )

    [2] => stdClass Object
        (
            [feature] => no
        )

    [3] => stdClass Object
        (
            [feature] => yes
        )

    [4] => stdClass Object
        (
            [feature] => yes
        )

    [5] => stdClass Object
        (
            [feature] => yes
        )

    [6] => stdClass Object
        (
            [feature] => yes
        )

    [7] => stdClass Object
        (
            [feature] => yes
        )

)
yes and no are the availability of a feature.
#6

[eluser]smilie[/eluser]
Oke, you are missing the products in that array...
Where do you have info about prod1 prod2 etc...?

Cheers,
Smilie
#7

[eluser]phpbeginner[/eluser]
Code:
Array
(
    [0] => stdClass Object
        (
            [name] => MusicPlayer
            [feature] => yes
        )

    [1] => stdClass Object
        (
            [name] => MusicPlayer
            [feature] => no
        )

    [2] => stdClass Object
        (
            [name] => MusicPlayer
            [feature] => no
        )

    [3] => stdClass Object
        (
            [name] => MusicPlayer
            [feature] => yes
        )

    [4] => stdClass Object
        (
            [name] => iPod
            [feature] => yes
        )

    [5] => stdClass Object
        (
            [name] => iPod
            [feature] => yes
        )

    [6] => stdClass Object
        (
            [name] => iPod
            [feature] => yes
        )

    [7] => stdClass Object
        (
            [name] => iPod
            [feature] => yes
        )

)
#8

[eluser]smilie[/eluser]
Code:
<table>
&lt;?php foreach($cmp as $item){?&gt;
<tr>
<td>&lt;?php echo $item->name;?&gt;</td>
<td>&lt;?php echo $item->feature;?&gt;</td>
</tr>
&lt;?php
}?&gt;
</table>

This way, they will be all one bellow another.
Is this oke - or do you need them to be in an (endless) line
prod1 prod2 prod3 prod4 ....
F1 F2 F3 F4 ....

Cheers,
Smilie
#9

[eluser]phpbeginner[/eluser]
Code:
MusicPlayer Bluetooth    yes
MusicPlayer headphone    no
MusicPlayer ExtraBaterry no
MusicPlayer music        yes
iPod        bluetooth    yes
iPod        headphone    yes
iPod        ExtraBaterry yes
iPod        music        yes
this is what is printed...... this is not looking as if two things are being compared . Smile
Ok,also added feature name
Code:
&lt;?php foreach($cmp as $item  ):?&gt;
<tr>
<td>&lt;?php echo $item->name;?&gt;</td>

<td>&lt;?php echo $item->Fname;?&gt;</td>
<td>&lt;?php echo $item->feature;?&gt;</td>
</tr>
&lt;?php
#10

[eluser]smilie[/eluser]
Oke, you will have to change your query, so that items are grouped by Fname;
Your result should look like:

Code:
Array
(
    [0] => stdClass Object
        (
            [0] => MusicPlayer
            (
                [0] => array
                (
                    [Fname] => Bluetooth
                    [feature] => yes
                )
                [1] => array
                (
                    [Fname] => headphone
                    [feature] => yes
                )
                [2] => array
                (
                    [Fname] => USB
                    [feature] => yes
                )
             )
         )
)

Then you can create table as you need it :-)

Cheers,
Smilie




Theme © iAndrew 2016 - Forum software by © MyBB