views:

71

answers:

1

I'm not getting back data from my DB like I'm expecting. I know that I can get data from the DB because I have other functions working. With this page, what I'm trying to do is the following:

If no postback, then I would like it to echo "No Category Selected"

If a category has been chosen, then I would like for it to get that data from the DB and show it on the page. I'm sure I can do this all in one view, I'm just not doing something right. Can someone help please?

the error i'm getting is:

A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: views/category_view.php Line Number: 25

as for db schema:

table: 'business' id, busname, busowner, busaddress, busicyt, busstate, buszip, busphone, webaddress, category, featured, userid.

table: 'category' id, catname, catdesc.

table: 'photos' id, photoname, photolocation, busid, userid.

table: 'specials' id, specname, specdesc, busid, userid.

table: 'videos' id, title, link, busid.

Pastebin: http://pastebin.com/AQqcvnAb

+1  A: 

Not sure at all what exactly is or isn't working for you. I tried this locally, and It is echoing "no category selected" correctly.

View:

<?php 
echo form_open('/site/categories');
echo form_fieldset(); ?>
<legend>Choose the Category of Business you are interested in.</legend>
<select name="catSelect">
<?php 
foreach ($catList->result() as $row){
    echo '<option value='.$row->id.'>'.$row->catname.'</option>';
}
echo form_submit('submit', 'Submit');
echo form_fieldset_close();
echo form_close(); 
?>
<table id="businessTable" class="tablesorter">
<thead><tr><th>Business Name</th><th>Photos</th><th>Videos</th><th>Specials</th></tr></thead>
<?php 
if(count($serviceVendors) > 0){
    foreach ($serviceVendors as $row){
        echo '<tr><td>'.$row->busname.'</td><td>';
        if(isset($row->photoname)){
                echo "photoname is set";
            }else{
                echo "photoname not set";
            }
            echo '</td><td>';
            if(isset($row->title)){
                echo "title set";
            }else{
                echo "title not set";
            }
            echo '</td><td>';
            if(isset($row->specname)){
                echo "specname set";
            }else{
                echo "specname not set";
            }
            echo '</td></tr>';
        }
    }else{
        echo "no category selected";
    }
?>
</table>

If you can be a little more specific (and post a db schema), I'll try harder.


OK. The problem is in your category_view:

<?php if(count($businessList) > 0) : foreach ($businessList as $svrow): ?>

needs to be:

<?php if(count($businessList) > 0) : foreach ($businessList->result() as $svrow): ?>

without the ->result() identifier it doesn't assign the object to svrow. So with this line, in place echo $svrow->busname; will echo the business name as expected.

stormdrain
the error i'm getting is:A PHP Error was encounteredSeverity: NoticeMessage: Trying to get property of non-objectFilename: views/category_view.phpLine Number: 25as for db schema:table: businessid, busname, busowner, busaddress, busicyt, busstate, buszip, busphone, webaddress, category, featured, useridtable: categoryid, catname, catdesctable: photosid, photoname, photolocation, busid, useridtable: specialsid, specname, specdesc, busid, useridtable: videosid, title, link, busid
Jason Shultz
I dunno, man. It looks like you're missing some methods in your model (frontPageList(), tank_auth()??). Again from here the category selection is working correctly. I'm not sure what line is causing your error (pastebin isn't clear). That error is to do with not looping through the returned object correctly, if memory serves. Try print_r 'ing the vars you're trying to get into the view.What exactly is on views/category_view.php Line Number: 25 What do you get if you try and `print_r($var_on_line_25);`? Is it a mysqlobject? array?
stormdrain
line 25 is: <td><?=$row->busname?></td>
Jason Shultz
I just want it to do something simple. If a query hasn't been made i want it to show that a query hasn't been made. if one is made I want it to show the data from the db that has been queried. :(
Jason Shultz
Ah. It might be conflicting with the other foreach var name. Change `foreach ($serviceVendors as $row):` to `foreach ($serviceVendors as $svRow):` and `<?=$row->busname?>` to `<?=$svRow->busname?>`. See what happens. If that doesn't work, what does `print_r($svRow->busname);` give?
stormdrain
ok, i tried it. here's what i got: Resource id #31Resource id #48Array()Array()01
Jason Shultz
It looks like another array is being returned from the db. Did you try looping through $row->busname?I can't reproduce your problem here because I don't have all the pieces. If you want, zip up your system folder and put a db dump in there too and upload it to rapidhsare or something.
stormdrain
here you go: http://drop.io/4hkspkb/asset/welcometojerome-com-rar
Jason Shultz
OK, I edited the answer above with the object solution.
stormdrain
Thank you, that seemed to work. I'm at least able to see data now. My code to check for postback doesn't seem to be working correctly, no matter what, the catID=6? Here's the code: if (!isset($_POST['catID'])) { $catID = '6'; } else { $catID = $_POST['catID']; }
Jason Shultz
how did you know I should add "->result()"? Under what circumstances is that required?
Jason Shultz
Try changing `$data['businessList'] = $this->Business_model->categoryPageList($catSelect);` to `$data['businessList'] = $this->Business_model->categoryPageList($catID);` in your site.php controller. See http://codeigniter.com/user_guide/database/results.html re: result()
stormdrain
I tried that earlier, but it didn't work.
Jason Shultz
Weird, I changed it to this: $this->load->model('Business_model'); if (!isset($_POST['catID'])) { $catID = '*'; } else { $catID = $_POST['catID']; }and it works now.
Jason Shultz
Thank you for your patience and your help. It is really appreciated.
Jason Shultz