duangang4940 2010-03-30 04:14
浏览 256
已采纳

回发问题? 没有从数据库获取数据

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条回答 默认 最新

  • dtotwai720621 2010-03-30 19:50
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值