Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何通过for循环显示数据库中特定项的信息?_Python_Jquery_Html_Web2py - Fatal编程技术网

Python 如何通过for循环显示数据库中特定项的信息?

Python 如何通过for循环显示数据库中特定项的信息?,python,jquery,html,web2py,Python,Jquery,Html,Web2py,我正在使用web2py框架,这就是我试图实现的目标 我在数据库中有不同地点的联系方式,这些不同地点的名称在页面中显示为链接,我想要的是,当我单击某个地点的链接名称时,该地点的联系方式将显示在工具提示中。但这不会发生!发生的是,当我单击地点的名称时,我会得到工具提示,不同地点的不同联系信息堆叠在一起 如上所述,我想要的是,当我单击某个地点的链接名称时,该地点的联系人详细信息将显示在工具提示中。,请任何人帮助我做好这项工作 型号代码 db.define_table('services',

我正在使用web2py框架,这就是我试图实现的目标
我在数据库中有不同地点的联系方式,这些不同地点的名称在页面中显示为链接,我想要的是,当我单击某个地点的链接名称时,该地点的联系方式将显示在工具提示中。但这不会发生!发生的是,当我单击地点的名称时,我会得到工具提示,不同地点的不同联系信息堆叠在一起

如上所述,我想要的是,当我单击某个地点的链接名称时,该地点的联系人详细信息将显示在工具提示中。,请任何人帮助我做好这项工作

型号代码

db.define_table('services',
            Field('service_name', requires=IS_NOT_EMPTY()),
           format='%(service_name)s', migrate=False, fake_migrate=True)

db.define_table('company',
            Field('logo', 'upload'),
            Field('company_name', requires=IS_NOT_EMPTY()),
            Field('services', 'reference services'),
            #Field('tlamelo', 'reference tlamelo'),
            Field('product', 'reference product'),
            Field('tel', requires=IS_NOT_EMPTY()),
            Field('email', requires=IS_NOT_EMPTY()),
            Field('fax', requires=IS_NOT_EMPTY()),
            Field('cell', requires=IS_NOT_EMPTY()),
            Field('facebook', requires=IS_NOT_EMPTY()),
            Field('twitter', requires=IS_NOT_EMPTY()),
            Field('website', requires=IS_NOT_EMPTY()),
            Field('postal_address', requires=IS_NOT_EMPTY()),
            Field('located_at', requires=IS_NOT_EMPTY()), migrate=False, fake_migrate=True)
#branch1 {outline:none; position: relative; font-weight: bold;}
#branch1 {text-decoration:none;}
span.contacts1
{ 
    display:inline; 
    position:absolute; 
    color:#111; 
    border:1px solid #000000;
    background: #000000; 
    opacity: 0.9; 
    color: white; 
    font-weight: bold; 
    font-size: small; 
    border:1px solid #000000; 
    border-radius: 25px;/*border-radius: 5px 100px 5px;*/
    z-index:1; 
    left: 40px; 
    display:none; 
    padding:14px 15px; 
    margin-top:-56px; 
    margin-left:70px; 
    width:500px; 
    line-height:16px;line-height:20px;
}
def companies():
    results=db.services(request.args(0))
    rslts=db(db.company.services==results.id).select(db.company.ALL, orderby=db.company.company_name)
    return locals()
<script>
        $(document).ready(function(){
        $('.branch1').click(function(e) {
            $(this).each(function(){
                $('.contacts1').fadeIn();
            e.preventDefault();
        });
        });
         $('img#close').click(function(e)
         {
             $('.contacts1').fadeOut();
             e.preventDefault();
         });
        });
    </script>


<div class="comps">
<span class="companies">COMPANIES (A-F)</span><br /><br />
{{letters=['A', 'B', 'C', 'D', 'E', 'F']
for company in rslts:
    if company.company_name[0] in letters:
company.company_name
}}

<a href="#" id="branch1" class="branch1 branches">{{=company.company_name}}</a><br />
<span class="contacts1">
<a href="#"><img src="{{=URL('static', 'images/close.png')}}" style="width: 50px; position: absolute; top:0px;right:0px;" id="close"/></a>
<div class="info" id="logo">
   <img id="companyLogo" width="140px" src="{{=URL('download',args=company.logo)}}" /><br />
   <span style="position: absolute; bottom:0px; left: 10px;">SESOA&trade</span>
</div>


<div class="info" style="padding-left:5px; border-left: solid 1px white;" id="details">
    <span class="companyName">{{=company.company_name}}</span>
    <hr class="divider" />
    <span class="contact" id="cell">TEL: </spanM <strongstyle="color:green;">{{=company.tel}}</strong><br />
<span class="contact" id="cell">EM@IL: </span> <strong style="color:green;">{{=company.email}}</strong><br />
<span class="contact" id="cell">CELL: </span><strong style="color:green;">{{=company.cell}}</strong><br />
<span class="contact" id="fb">Facebook: </span>  <strong style="color:green;">{{=company.facebook}}</strong><br />

<span class="contact" id="twit">Twitter: </span> <strong style="color:green;">{{=company.twitter}}</strong><br />
    <a href="{{=company.website}}" target="_blank"><span class="contact" id="e_mail">WEBSITE: </span> <strong style="color:green;">{{=company.website}}</strong></span></a><br />

<span class="contact" id="cell">FAX: </span> <strong style="color:green;">{{=company.fax}}</strong><br />
<span class="contact" id="cell">LOCATION: </span> <strong style="color:green;">{{=company.located_at}}</strong><br />
</div>
</span>

         {{pass}}
        {{pass}}
</div>
CSS工具提示代码

db.define_table('services',
            Field('service_name', requires=IS_NOT_EMPTY()),
           format='%(service_name)s', migrate=False, fake_migrate=True)

db.define_table('company',
            Field('logo', 'upload'),
            Field('company_name', requires=IS_NOT_EMPTY()),
            Field('services', 'reference services'),
            #Field('tlamelo', 'reference tlamelo'),
            Field('product', 'reference product'),
            Field('tel', requires=IS_NOT_EMPTY()),
            Field('email', requires=IS_NOT_EMPTY()),
            Field('fax', requires=IS_NOT_EMPTY()),
            Field('cell', requires=IS_NOT_EMPTY()),
            Field('facebook', requires=IS_NOT_EMPTY()),
            Field('twitter', requires=IS_NOT_EMPTY()),
            Field('website', requires=IS_NOT_EMPTY()),
            Field('postal_address', requires=IS_NOT_EMPTY()),
            Field('located_at', requires=IS_NOT_EMPTY()), migrate=False, fake_migrate=True)
#branch1 {outline:none; position: relative; font-weight: bold;}
#branch1 {text-decoration:none;}
span.contacts1
{ 
    display:inline; 
    position:absolute; 
    color:#111; 
    border:1px solid #000000;
    background: #000000; 
    opacity: 0.9; 
    color: white; 
    font-weight: bold; 
    font-size: small; 
    border:1px solid #000000; 
    border-radius: 25px;/*border-radius: 5px 100px 5px;*/
    z-index:1; 
    left: 40px; 
    display:none; 
    padding:14px 15px; 
    margin-top:-56px; 
    margin-left:70px; 
    width:500px; 
    line-height:16px;line-height:20px;
}
def companies():
    results=db.services(request.args(0))
    rslts=db(db.company.services==results.id).select(db.company.ALL, orderby=db.company.company_name)
    return locals()
<script>
        $(document).ready(function(){
        $('.branch1').click(function(e) {
            $(this).each(function(){
                $('.contacts1').fadeIn();
            e.preventDefault();
        });
        });
         $('img#close').click(function(e)
         {
             $('.contacts1').fadeOut();
             e.preventDefault();
         });
        });
    </script>


<div class="comps">
<span class="companies">COMPANIES (A-F)</span><br /><br />
{{letters=['A', 'B', 'C', 'D', 'E', 'F']
for company in rslts:
    if company.company_name[0] in letters:
company.company_name
}}

<a href="#" id="branch1" class="branch1 branches">{{=company.company_name}}</a><br />
<span class="contacts1">
<a href="#"><img src="{{=URL('static', 'images/close.png')}}" style="width: 50px; position: absolute; top:0px;right:0px;" id="close"/></a>
<div class="info" id="logo">
   <img id="companyLogo" width="140px" src="{{=URL('download',args=company.logo)}}" /><br />
   <span style="position: absolute; bottom:0px; left: 10px;">SESOA&trade</span>
</div>


<div class="info" style="padding-left:5px; border-left: solid 1px white;" id="details">
    <span class="companyName">{{=company.company_name}}</span>
    <hr class="divider" />
    <span class="contact" id="cell">TEL: </spanM <strongstyle="color:green;">{{=company.tel}}</strong><br />
<span class="contact" id="cell">EM@IL: </span> <strong style="color:green;">{{=company.email}}</strong><br />
<span class="contact" id="cell">CELL: </span><strong style="color:green;">{{=company.cell}}</strong><br />
<span class="contact" id="fb">Facebook: </span>  <strong style="color:green;">{{=company.facebook}}</strong><br />

<span class="contact" id="twit">Twitter: </span> <strong style="color:green;">{{=company.twitter}}</strong><br />
    <a href="{{=company.website}}" target="_blank"><span class="contact" id="e_mail">WEBSITE: </span> <strong style="color:green;">{{=company.website}}</strong></span></a><br />

<span class="contact" id="cell">FAX: </span> <strong style="color:green;">{{=company.fax}}</strong><br />
<span class="contact" id="cell">LOCATION: </span> <strong style="color:green;">{{=company.located_at}}</strong><br />
</div>
</span>

         {{pass}}
        {{pass}}
</div>
控制器代码

db.define_table('services',
            Field('service_name', requires=IS_NOT_EMPTY()),
           format='%(service_name)s', migrate=False, fake_migrate=True)

db.define_table('company',
            Field('logo', 'upload'),
            Field('company_name', requires=IS_NOT_EMPTY()),
            Field('services', 'reference services'),
            #Field('tlamelo', 'reference tlamelo'),
            Field('product', 'reference product'),
            Field('tel', requires=IS_NOT_EMPTY()),
            Field('email', requires=IS_NOT_EMPTY()),
            Field('fax', requires=IS_NOT_EMPTY()),
            Field('cell', requires=IS_NOT_EMPTY()),
            Field('facebook', requires=IS_NOT_EMPTY()),
            Field('twitter', requires=IS_NOT_EMPTY()),
            Field('website', requires=IS_NOT_EMPTY()),
            Field('postal_address', requires=IS_NOT_EMPTY()),
            Field('located_at', requires=IS_NOT_EMPTY()), migrate=False, fake_migrate=True)
#branch1 {outline:none; position: relative; font-weight: bold;}
#branch1 {text-decoration:none;}
span.contacts1
{ 
    display:inline; 
    position:absolute; 
    color:#111; 
    border:1px solid #000000;
    background: #000000; 
    opacity: 0.9; 
    color: white; 
    font-weight: bold; 
    font-size: small; 
    border:1px solid #000000; 
    border-radius: 25px;/*border-radius: 5px 100px 5px;*/
    z-index:1; 
    left: 40px; 
    display:none; 
    padding:14px 15px; 
    margin-top:-56px; 
    margin-left:70px; 
    width:500px; 
    line-height:16px;line-height:20px;
}
def companies():
    results=db.services(request.args(0))
    rslts=db(db.company.services==results.id).select(db.company.ALL, orderby=db.company.company_name)
    return locals()
<script>
        $(document).ready(function(){
        $('.branch1').click(function(e) {
            $(this).each(function(){
                $('.contacts1').fadeIn();
            e.preventDefault();
        });
        });
         $('img#close').click(function(e)
         {
             $('.contacts1').fadeOut();
             e.preventDefault();
         });
        });
    </script>


<div class="comps">
<span class="companies">COMPANIES (A-F)</span><br /><br />
{{letters=['A', 'B', 'C', 'D', 'E', 'F']
for company in rslts:
    if company.company_name[0] in letters:
company.company_name
}}

<a href="#" id="branch1" class="branch1 branches">{{=company.company_name}}</a><br />
<span class="contacts1">
<a href="#"><img src="{{=URL('static', 'images/close.png')}}" style="width: 50px; position: absolute; top:0px;right:0px;" id="close"/></a>
<div class="info" id="logo">
   <img id="companyLogo" width="140px" src="{{=URL('download',args=company.logo)}}" /><br />
   <span style="position: absolute; bottom:0px; left: 10px;">SESOA&trade</span>
</div>


<div class="info" style="padding-left:5px; border-left: solid 1px white;" id="details">
    <span class="companyName">{{=company.company_name}}</span>
    <hr class="divider" />
    <span class="contact" id="cell">TEL: </spanM <strongstyle="color:green;">{{=company.tel}}</strong><br />
<span class="contact" id="cell">EM@IL: </span> <strong style="color:green;">{{=company.email}}</strong><br />
<span class="contact" id="cell">CELL: </span><strong style="color:green;">{{=company.cell}}</strong><br />
<span class="contact" id="fb">Facebook: </span>  <strong style="color:green;">{{=company.facebook}}</strong><br />

<span class="contact" id="twit">Twitter: </span> <strong style="color:green;">{{=company.twitter}}</strong><br />
    <a href="{{=company.website}}" target="_blank"><span class="contact" id="e_mail">WEBSITE: </span> <strong style="color:green;">{{=company.website}}</strong></span></a><br />

<span class="contact" id="cell">FAX: </span> <strong style="color:green;">{{=company.fax}}</strong><br />
<span class="contact" id="cell">LOCATION: </span> <strong style="color:green;">{{=company.located_at}}</strong><br />
</div>
</span>

         {{pass}}
        {{pass}}
</div>
查看代码

db.define_table('services',
            Field('service_name', requires=IS_NOT_EMPTY()),
           format='%(service_name)s', migrate=False, fake_migrate=True)

db.define_table('company',
            Field('logo', 'upload'),
            Field('company_name', requires=IS_NOT_EMPTY()),
            Field('services', 'reference services'),
            #Field('tlamelo', 'reference tlamelo'),
            Field('product', 'reference product'),
            Field('tel', requires=IS_NOT_EMPTY()),
            Field('email', requires=IS_NOT_EMPTY()),
            Field('fax', requires=IS_NOT_EMPTY()),
            Field('cell', requires=IS_NOT_EMPTY()),
            Field('facebook', requires=IS_NOT_EMPTY()),
            Field('twitter', requires=IS_NOT_EMPTY()),
            Field('website', requires=IS_NOT_EMPTY()),
            Field('postal_address', requires=IS_NOT_EMPTY()),
            Field('located_at', requires=IS_NOT_EMPTY()), migrate=False, fake_migrate=True)
#branch1 {outline:none; position: relative; font-weight: bold;}
#branch1 {text-decoration:none;}
span.contacts1
{ 
    display:inline; 
    position:absolute; 
    color:#111; 
    border:1px solid #000000;
    background: #000000; 
    opacity: 0.9; 
    color: white; 
    font-weight: bold; 
    font-size: small; 
    border:1px solid #000000; 
    border-radius: 25px;/*border-radius: 5px 100px 5px;*/
    z-index:1; 
    left: 40px; 
    display:none; 
    padding:14px 15px; 
    margin-top:-56px; 
    margin-left:70px; 
    width:500px; 
    line-height:16px;line-height:20px;
}
def companies():
    results=db.services(request.args(0))
    rslts=db(db.company.services==results.id).select(db.company.ALL, orderby=db.company.company_name)
    return locals()
<script>
        $(document).ready(function(){
        $('.branch1').click(function(e) {
            $(this).each(function(){
                $('.contacts1').fadeIn();
            e.preventDefault();
        });
        });
         $('img#close').click(function(e)
         {
             $('.contacts1').fadeOut();
             e.preventDefault();
         });
        });
    </script>


<div class="comps">
<span class="companies">COMPANIES (A-F)</span><br /><br />
{{letters=['A', 'B', 'C', 'D', 'E', 'F']
for company in rslts:
    if company.company_name[0] in letters:
company.company_name
}}

<a href="#" id="branch1" class="branch1 branches">{{=company.company_name}}</a><br />
<span class="contacts1">
<a href="#"><img src="{{=URL('static', 'images/close.png')}}" style="width: 50px; position: absolute; top:0px;right:0px;" id="close"/></a>
<div class="info" id="logo">
   <img id="companyLogo" width="140px" src="{{=URL('download',args=company.logo)}}" /><br />
   <span style="position: absolute; bottom:0px; left: 10px;">SESOA&trade</span>
</div>


<div class="info" style="padding-left:5px; border-left: solid 1px white;" id="details">
    <span class="companyName">{{=company.company_name}}</span>
    <hr class="divider" />
    <span class="contact" id="cell">TEL: </spanM <strongstyle="color:green;">{{=company.tel}}</strong><br />
<span class="contact" id="cell">EM@IL: </span> <strong style="color:green;">{{=company.email}}</strong><br />
<span class="contact" id="cell">CELL: </span><strong style="color:green;">{{=company.cell}}</strong><br />
<span class="contact" id="fb">Facebook: </span>  <strong style="color:green;">{{=company.facebook}}</strong><br />

<span class="contact" id="twit">Twitter: </span> <strong style="color:green;">{{=company.twitter}}</strong><br />
    <a href="{{=company.website}}" target="_blank"><span class="contact" id="e_mail">WEBSITE: </span> <strong style="color:green;">{{=company.website}}</strong></span></a><br />

<span class="contact" id="cell">FAX: </span> <strong style="color:green;">{{=company.fax}}</strong><br />
<span class="contact" id="cell">LOCATION: </span> <strong style="color:green;">{{=company.located_at}}</strong><br />
</div>
</span>

         {{pass}}
        {{pass}}
</div>

$(文档).ready(函数(){
$('.branch1')。单击(函数(e){
$(this).each(function(){
$('.contacts1').fadeIn();
e、 预防默认值();
});
});
$('img#close')。单击(函数(e)
{
$('.contacts1').fadeOut();
e、 预防默认值();
});
});
公司(A-F)

{{字母=['A','B','C','D','E','F'] 对于rslts中的公司: 如果公司名称[0]以字母表示: 公司名称 }}

SESOA与贸易 {{=company.company_name}

电话:在点击处理程序中,联系人通过以下方式显示:

$('.contacts1').fadeIn()
但是,在
for
循环中,每个联系人都会获得一个“contacts1”类,因此上面的选择器会在单击任何链接时选择要淡入的所有联系人

相反,您必须为每个联系人添加唯一标识符,并在单击其链接时仅选择该联系人

尝试更改:

<a href="#" id="branch1" class="branch1 branches">{{=company.company_name}}</a><br />
<span class="contacts1">
另外,请注意,在HTML页面中,每个
id
属性必须是唯一的,但在每个循环中重复使用相同的
id
值(即,“branch1”、“close”、“logo”)。您甚至可以在循环的一次迭代中多次重复使用“cell”
id
。您甚至不清楚是否需要所有这些
id
,但如果确实需要其中任何一个,请确保它们是唯一的(例如,类似于
“{{='branch%s'%company.id}}”