Mysql PHP搜索内部加入

时间:2014-01-30 08:14:12

标签: php mysql sql

我正在使用从我的内部联接查询中输出的MYSql数据库: enter image description here

使用此查询(工作正常)

$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'];

2 个答案:

答案 0 :(得分:0)

首先你的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'];
}

答案 1 :(得分:0)

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