Php 从zend framework中的两个表中获取数据
我已经开始学习Zend框架3天了,我被卡住了 我有一个网页,允许用户在选择框中选择手机品牌:苹果和三星。选择后,mySQL的数据将显示在下面(对于每个品牌,数据将不同)。现在我想实现一个搜索函数,它将列出所有匹配结果(对每个表计数)。在基于PHP的环境中,这将很容易使用mysql查询Php 从zend framework中的两个表中获取数据,php,mysql,zend-framework,Php,Mysql,Zend Framework,我已经开始学习Zend框架3天了,我被卡住了 我有一个网页,允许用户在选择框中选择手机品牌:苹果和三星。选择后,mySQL的数据将显示在下面(对于每个品牌,数据将不同)。现在我想实现一个搜索函数,它将列出所有匹配结果(对每个表计数)。在基于PHP的环境中,这将很容易使用mysql查询,就像一样,但现在在Zend框架中,我不知道应该做什么。以下是我迄今为止的代码,但它不起作用: index.phtml <script> function change(){ do
,就像
一样,但现在在Zend框架中,我不知道应该做什么。以下是我迄今为止的代码,但它不起作用:
index.phtml
<script>
function change(){
document.getElementById("brand").submit();
}
</script>
<h3>Choose your brand</h3>
<form id="brand" method="post">
<select name="a" onchange="change();">
<option selected="selected"></option>
<option value="apple" >Apple</option>
<option value="samsung">Samsung</option>
</select>
</form>
<h3>Choose your product or search for your devices </h3>
<form id="search" method="post">
<input type="text" name="search" placeholder="Enter device name">
<input type="submit" name="subsearch">
</form>
<p><table border="2">
<tr>
<th>ID</th>
<th>Product Name</th>
<th>Manage</th>
</tr>
<?php
session_start();
$_SESSION['a'] = $_POST['a'];
if($_POST['a'] == 'apple'){
foreach ($this->apple as $apple):
?>
<tr>
<td><?php echo $apple['id'] . ""; ?></td>
<td><?php echo $apple['name'] . ""; ?></td>
<td colspan="2"><a href="<?php echo $this->url(array('controller' => 'index', 'action' => 'edit', 'id' => $apple['id'])) ?>"> Edit </a>
<a href="<?php echo $this->url(array('controller' => 'index', 'action' => 'deleteapp', 'id' => $apple['id'])) ?>"> Delete </a></td>
</tr>
<?php endforeach; ?>
</p></table>
<a href="<?php echo $this->url(array('controller' => 'index', 'action' => 'showform'), 'show') ?>">Add new devices</a><?php } ?>
<?php
if($_POST['a'] == 'samsung'){
foreach ($this->samsung as $samsung):
?>
<tr>
<td><?php echo $samsung['id'] . ""; ?></td>
<td><?php echo $samsung['name'] . ""; ?></td>
<td colspan="2"><a href="<?php echo $this->url(array('controller' => 'index', 'action' => 'edit', 'id' => $samsung['id'])) ?>"> Edit </a>
<a href="<?php echo $this->url(array('controller' => 'index', 'action' => 'deletesam', 'id' => $samsung['id'])) ?>"> Delete </a></td>
</tr>
<?php endforeach; ?>
</p></table>
<a href="<?php echo $this->url(array('controller' => 'index', 'action' => 'showf'), 'show') ?>">Add new devices</a><?php } ?>
试着改变这部分
$select->where('name LIKE ?', $userName . '%');
像这样(但请不要忘记将表{tablename,anothertable}和列{name,姓氏,email}替换为您在项目中使用的表)
->join(“另一个表”,“另一个表.name=tablename.name,数组('name','name','email'))->顺序(“另一个表.name ASC”)
另一个表
-要加入的表的名称anothertable.name=tablename.name
-将从另一个表的相应行中添加列的条件数组(“名称”、“姓氏”、“电子邮件”)
-查询将添加列名称->顺序(“anothertable.name ASC”)
-这将说明要排序的列
这里有更多信息
希望这对你有帮助
$select->where('name LIKE ?', $userName . '%');
$select->from('tablename', 'name')
->where('tablename.name LIKE ?', $userName . '%')
->join('anothertable', 'anothertable.name = tablename.name', array('name', 'surname', 'email'))
->order("anothertable.name ASC");