0

I'm new to php and I'm trying to understand the basics of how my site is interacting with the database. can someone take a quick look and tell me if they see something wrong with the following code?

Here's the function in the controller

class Spoonful extends C_Controller {


    public function index() {

        $collectives = $this - > get_mailchimp_collectives();
        $this - > data['collectives'] = $collectives;

        $this - > load - > view('spoonful');

    }

    private function get_mailchimp_collectives() {

        $constraints['select'] = 'collective.*, member.username, image.path AS avatar';

        $constraints['join'] = array(
        array('table' = > 'member', 'on' = > 'member.member_id=collective.member_id'), array('table' = > 'collective_tag', 'on' = > 'collective_tag.collective_id=collective.collective_id'), array('table' = > 'tag', 'on' = > 'tag.tag_id=collective_tag.tag_id'), array('table' = > 'image', 'on' = > 'image.image_id=member.avatar_id'));

        $constraints['where'] = array('tag.value' = > 'mailchimp');
        $constraints['order_by'] = array('collective.added' = > 'DESC');
        $constraints['limit'] = array('lower' = > 3);

        $collectives = $this - > db - > get('collective', $constraints);

        if (!empty($collectives['result_set'])) return $collectives['result_set'];


        return NULL;
    }



}

and here's the snippet of the view:

<!-- START COLLECTIVES -->
<?php if (!empty($collectives)){?>
    <?php foreach ($collectives AS $collective){?>
    <tr>
        <td bgcolor="#FFFFFF">

            <table cellpadding="0" cellspacing="0">
                <tr>
                    <td colspan="9" style="font-size:0;line-height:0;"><img src="<?php echo site_url("images/spoonful/qc_table_top.gif"); ?>"  width="566" height="17"></td>
                </tr>
                <tr>
                    <td width="1" bgcolor="#D9D9D9" style="font-size:0;line-height:0;"><img src="<?php echo site_url("images/spoonful/none.gif"); ?>" width="1" height="1"></td>
                    <td width="13" style="font-size:0;line-height:0;"><img src="<?php echo site_url("images/spoonful/none.gif");?>" width="13" height="1"></td>
                    <td width="66" valign="top">
                        <table cellpadding="0" cellspacing="0">
                            <tr>
                                <td colspan="3" style="font-size:0;line-height:0;"><img src="<?php echo site_url("images/spoonful/avatar_top.gif"); ?>" width="66" height="5"></td>
                            </tr>
                            <tr>
                                <td style="font-size:0;line-height:0;"><img src="<?php echo site_url("images/spoonful/avatar_right.gif"); ?>" width="5" height="45"></td>
                                <td style="font-size:0;line-height:0;"><a href="<?php echo site_url("people/{$collective['username']}"); ?>" target="_blank"><img src="<?php echo $collective['avatar']; ?>" width="46" height="45" border="0"></a></td>
                                <td style="font-size:0;line-height:0;"><img src="<?php echo site_url("images/spoonful/avatar_spike.gif"); ?>" width="15" height="45"></td> 
                            </tr>
                            <tr>
                                <td colspan="3" style="font-size;0;line-height:0;"><img src="<?php echo site_url("images/spoonful/avatar_bottom.gif"); ?>" width="66" height="5"></td>
                            </tr>
                        </table>                                                    </td>
                    <td width="15" style="font-size:0;line-height:0;"><img src="<?php echo site_url("images/spoonful/none.gif"); ?>" width="15" height="1"></td>
                    <td width="338" valign="top">

                        <a href="<?php echo site_url("question/{$collective['collective_id']}/{$this->utilities->get_url_title($collective['title'])}"); ?>" style="text-decoration:none;"><font style="font-size:15px;line-height:18px;font-weight:bold;" color="#242424" face="Arial, Helvetica, sans-serif"><?php echo $collective['title']; ?></font></a><br>
                        <font style="font-size:11px;" color="#A5A5A5" face="Arial, Helvetica, sans-serif">by <a style="text-decoration:none;" href="<?php echo site_url("people/{$collective['username']}"); ?>"><font color="#2294B8"><?php echo $collective['username']; ?></font></a></font>                                                 </td>
                    <td width="30" style="font-size:0;line-height:0;"><img src="<?php echo site_url("images/spoonful/none.gif"); ?>" width="30" height="1"></td>
                    <td width="81" valign="top">
                        <table cellpadding="0" cellspacing="0">
                            <tr>
                                <td style="font-size:0;line-height:0;"><a href="<?php echo site_url("question/{$collective['collective_id']}/{$this->utilities->get_url_title($collective['title'])}");?>"><img src="<?php echo site_url("images/spoonful/answer.gif"); ?>" width="81" height="27" border="0" alt="ANSWER"></a></td>
                            </tr>
                            <tr>
                                <td style="font-size:0;line-height:0;"><img src="<?php echo site_url("images/spoonful/none.gif"); ?>" width="1" height="8"></td>
                            </tr>
                            <tr>
                                <td width="81" align="center" style="text-align:center;"><a style="text-decoration:none;" href="<?php echo site_url("question/{$collective['collective_id']}/{$this->utilities->get_url_title($collective['title'])}");?>"><font style="font-size:11px;" color="#8E8E8E" face="Arial, Helvetica, sans-serif">View Answers</font></a></td>
                            </tr>
                        </table>                                                    </td>
                    <td width="21" style="font-size:0;line-height:0;"><img src="<?php echo site_url("images/spoonful/none.gif");?>" width="21" height="1"></td>
                    <td width="1" bgcolor="#D9D9D9" style="font-size:0;line-height:0;"><img src="<?php echo site_url("images/spoonful/none.gif"); ?>" width="1" height="1"></td>    
                </tr>
                <tr>
                    <td colspan="9" style="font-size:0;line-height:0;"><img src="<?php echo site_url("images/spoonful/qc_table_bottom.gif"); ?>" width="566" height="21"></td>
                </tr>
            </table>                                        </td>
    </tr>
    <tr>
        <td style="font-size=0;line-height:0;"><img src="<?php echo site_url("images/spoonful/none.gif"); ?>" width="1" height="9"></td>
    </tr>
    <?php }?>
<?php }?>

but for some reason, i just can't get it to load. if i comment out the lines:

if (!empty($collectives['result_set']))
   return $collectives['result_set'];

then the view loads with no data, but when i leave it in, i get a blank page. would love some advice.

thanks so much!

1
  • make sure error reporting is enabled so you can see any errors that PHP is throwing Commented May 2, 2011 at 5:53

1 Answer 1

2

Your two problems that I can see are, first of all the Codeigniter Controller is called CI_Controller not C_Controller (in the version that you're using at least) so:

class Spoonful extends C_Controller {

should be

class Spoonful extends CI_Controller {

Additionally you're not actually passing any data to the view, you do so with the second parameter of the view load function so:

   $this - > data['collectives'] = $collectives;

   $this - > load - > view('spoonful');

should be

   $this - > data['collectives'] = $collectives;

   $this - > load - > view('spoonful', $this->data);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.