繁体   English   中英

Mysql PHP搜索内部联接

[英]Mysql PHP Search Inner Join

我正在使用MYSql数据库,它从我的内部联接查询中输出如下: 在此处输入图片说明

使用此查询(效果很好)

$result = mysql_query( "
select
   `account`.`name`, `customfield`.`value`, `note`.`occurredondatetime` noteid 
       from  (`note`, `activity`, `ownedsecurableitem` ownedsecurableitem1)
left join `activity_item` on `activity_item`.`activity_id` = `activity`.`id` 
  left join `item` on `item`.`id` = `activity_item`.`item_id` 
    left join `securableitem` on `securableitem`.`item_id` = `item`.`id` 
left join `ownedsecurableitem` on `ownedsecurableitem`.`securableitem_id` = `securableitem`.`id` 
  left join `account` on `account`.`ownedsecurableitem_id` = `ownedsecurableitem`.`id` 
    left join `_user` on `_user`.`id` = `ownedsecurableitem1`.`owner__user_id` 
left join `customfield` on `customfield`.`id` = `account`.`salecyclecstm_customfield_id`

where (`account`.`name` IS NOT NULL) 
  and `activity`.`id` = `note`.`activity_id` 
    and `ownedsecurableitem1`.`id` = `activity`.`ownedsecurableitem_id`
      and (`note`.`occurredondatetime` IS NOT NULL)
       and name='".$_POST['query']."'";

 ORDER BY occurredondatetime DESC

")

 or die("SELECT Error: ".mysql_error());    
  print "<table border=1 >\n";  
   $account = "Account";
    $sale = "Sale Cycle";
     $date = "Date";
      print "\t<td><bold><b>$account<b></td>\n";
       print "\t<td><bold><b>$sale<b></td>\n";
 print "\t<td><bold><b>$date<b></td>\n";
  while ($get_info = mysql_fetch_row($result)){  
   print "<P>";
    print "<tr>\n";  
     foreach ($get_info as $field) 
      print "\t<td>$field</td>\n";
       print "</tr>\n";  
        } 
         print "</table>\n";

我的问题是:我将如何创建一个可以搜索该帐户的表单(文本框输入),该表单将显示“销售周期”和“日期”字段(不在表格中)? 理想情况下,我希望它在同一页面上输出,所以Java还是Ajax?

我有:HTML

<form name="form1" id="form1" method="post" action="search.php"> //change here
Select Name :
<input type="text" name="query" /> 
<input type="submit" name="submit" id="submit" value="search" />
</form>

的PHP

$query=mysql_query($select) or die($select);
$numrow=mysql_num_rows($query);
if($numrow != 0)
{
while($row=mysql_fetch_array($query))
{   
<?php echo $row['name'];
<?php echo $row['SalesStages'];

首先您的php编码是错误的。您在不需要的地方使用<?php 。请删除它,并且必须在执行之前编写查询。

<form name="form1" id="form1" method="post" action="search.php"> //change here
Select Name :
<input type="text" name="query" /> 
<input type="submit" name="submit" id="submit" value="search" />
</form>


$query="select * from table where Account='".$_POST['query']."'";
$result = mysql_query($query) or die (mysql_error());
$numrow=mysql_num_rows($result);

while($row=mysql_fetch_array($query))
{   
 echo $row['name'];
 echo $row['SalesStages'];
}

您可以使用javascript创建动态表,这是一个示例: http : //listjs.com/它允许您搜索和排序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM