首先让我说我对PHP很新。我很开心尝试并学习它!现在我遇到了一些不在我联盟中的东西。
我想要做的是:只返回某个列中有X的结果。
屏幕截图部分是德语,但我会解释:
它看起来像什么
目前我有2个搜索表单。我的代码可能非常糟糕或者可以简单化。我只是不知道如何。问题是大部分是在1个表中,1个部分在不同的表中。
现在我想把它放在哪里,如果我搜索一个产品,它应该只放出“BSTHINW3”栏中有X的产品
我现在使用的两个脚本使其成为可能:
<?php
mysql_connect("localhost", "root", "") or die("Fehler: ".mysql_error());
mysql_select_db("database") or die(mysql_error());
?>
<html>
<head>
<title>Artikelsuche</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<form action="index.php" method="GET">
Artikelnummer :
<input type="text" name="query" />
<input type="submit" value="Search" />
</form>
<br>
<div id="aktivsu">
<form action="index2.php" method="GET">
Aktiv :
<input type="text" name="query2" />
<input type="submit" value="Active" />
</form>
</div>
<br>
<?php
$query = $_GET['query'];
$min_length = 1;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT BSTARTMASS, BSTKATNR, BSTLIEFBST,
BSTARTBES1, BSTANF, BSTLIEFMIN,
BSTSTLIO, BSTMIND, BSTKUMST,
BSTKUMVK, BSTKUMER
FROM elebest
WHERE (`BSTLIEFBST` LIKE '%".$query."%'
OR `BSTKATNR` LIKE '%".$query."%'
OR `BSTLIEFTXT` LIKE '%".$query."%')")
or die(mysql_error());
$raw_results = mysql_query("SELECT BSTARTMASS, BSTKATNR, BSTLIEFBST,
BSTARTBES1, BSTANF, BSTLIEFMIN,
BSTSTLIO, BSTMIND, BSTKUMSTVJ,
BSTKUMVKVJ, BSTKUMERVJ,
BSTKUMST, BSTKUMVK, BSTKUMER
FROM vorjahr
WHERE (`BSTLIEFBST` LIKE '%".$query."%'
OR `BSTKATNR` LIKE '%".$query."%'
OR `BSTLIEFTXT` LIKE '%".$query."%')")
or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo '<br>' ;
echo '<br>' ;
echo '<br>' ;
echo "<div id='artnr'> Number: ".$results['BSTKATNR']. "</div>";
echo "<div id='lfnr'> Nr LF / Code : ".$results['BSTLIEFBST']."</div>";
echo '<br>' ;
echo "<div id='3'> Desc: ".$results['BSTARTBES1']."</div>";
echo '<br>' ;
echo "<div id='bestandverf'>" ;
echo "Bestand : ".$results['BSTANF']."";
echo '<br>' ;
echo "Verfügbar : ".$results['BSTSTLIO']."";
echo "</div>" ;
echo "<div id='minbes'>" ;
echo "Mindestbestellung : ".$results['BSTLIEFMIN']."";
echo '<br>' ;
echo "Mindestbestand : ".$results['BSTMIND']."";
echo "</div>" ;
echo "<div id='verkakt'>" ;
echo "Current Year ".$results['BSTARTMASS']."";
echo "</div>" ;
echo '<br>';
echo "<div id='aktjahr'>" ;
echo "Quantity : ".$results['BSTKUMST']."";
echo '<br>' ;
echo " Sales : ".$results['BSTKUMVK']." €";
echo '<br>' ;
echo " Income : ".$results['BSTKUMER']." €";
echo "</div>" ;
echo '<br>';
echo "<div id='verkvj'>" ;
echo "Last Year ".$results['BSTARTMASS']."";
echo "</div>" ;
echo "<div id='vj'>" ;
echo "Quantity : ".$results['BSTKUMSTVJ']."";
echo '<br>';
echo "Sales : ".$results['BSTKUMVKVJ']." €";
echo '<br>';
echo "Income : ".$results['BSTKUMERVJ']." €";
echo "</div>" ;
}
}
else{
echo "No results";
}
}
else{
echo "Minimum input length : ".$min_length;
}
?>
</body>
<?php
mysql_connect("localhost", "root", "") or die("Fehler: ".mysql_error());
mysql_select_db("database") or die(mysql_error());
?>
<html>
<head>
<title>Artikelsuche</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<form action="index.php" method="GET">
Artikelnummer :
<input type="text" name="query" />
<input type="submit" value="Search" />
</form>
<br>
<div id="aktivsu">
<form action="index2.php" method="GET">
Aktiv :
<input type="text" name="query2" />
<input type="submit" value="Active" />
</form>
</div>
<br>
<?php
$query2 = $_GET['query2'];
$min_length = 0;
if(strlen($query2) >= $min_length){
$query2 = htmlspecialchars($query2);
$query2 = mysql_real_escape_string($query2);
$raw_results = mysql_query("SELECT BSTHINW3, BSTARTMASS, BSTKATNR,
BSTLIEFBST, BSTARTBES1, BSTANF,
BSTLIEFMIN, BSTSTLIO, BSTMIND,
BSTKUMST, BSTKUMVK, BSTKUMER
FROM elebest
WHERE (`BSTLIEFBST` LIKE '%".$query2."%'
OR `BSTKATNR` LIKE '%".$query2."%'
OR `BSTLIEFTXT` LIKE '%".$query2."%')")
or die(mysql_error());
$raw_results = mysql_query("SELECT BSTHINW3, BSTARTMASS, BSTKATNR,
BSTLIEFBST, BSTARTBES1, BSTANF,
BSTLIEFMIN, BSTSTLIO, BSTMIND,
BSTKUMSTVJ, BSTKUMVKVJ, BSTKUMERVJ,
BSTKUMST, BSTKUMVK, BSTKUMER
FROM vorjahr
WHERE (`BSTLIEFBST` LIKE '%".$query2."%'
OR `BSTKATNR` LIKE '%".$query2."%'
OR `BSTLIEFTXT` LIKE '%".$query2."%')
ORDER BY BSTHINW3")
or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo '<br>' ;
echo '<br>' ;
echo '<br>' ;
echo "<div id='artnr'> Number: ".$results['BSTKATNR']. "</div>";
echo "<div id='lfnr'>Nr LF / Code : ".$results['BSTLIEFBST']."</div>";
echo '<br>' ;
echo "<div id='3'> Desc: ".$results['BSTARTBES1']."</div>";
echo '<br>' ;
echo "<div id='bestandverf'>" ;
echo "Bestand : ".$results['BSTANF']."";
echo '<br>' ;
echo "Verfügbar : ".$results['BSTSTLIO']."";
echo "</div>" ;
echo "<div id='minbes'>" ;
echo "Mindestbestellung : ".$results['BSTLIEFMIN']."";
echo '<br>' ;
echo "Mindestbestand : ".$results['BSTMIND']."";
echo "</div>" ;
echo "<div id='verkakt'>" ;
echo "Current Year ".$results['BSTARTMASS']."";
echo "</div>" ;
echo '<br>';
echo "<div id='aktjahr'>" ;
echo " Quantity : ".$results['BSTKUMST']."";
echo '<br>' ;
echo " Sales : ".$results['BSTKUMVK']." €";
echo '<br>' ;
echo " Income : ".$results['BSTKUMER']." €";
echo "</div>" ;
echo '<br>';
echo "<div id='verkvj'>" ;
echo " Last Year ".$results['BSTARTMASS']."";
echo "</div>" ;
echo "<div id='vj'>" ;
echo "Quantity : ".$results['BSTKUMSTVJ']."";
echo '<br>';
echo "Sales : ".$results['BSTKUMVKVJ']." €";
echo '<br>';
echo "Income : ".$results['BSTKUMERVJ']." €";
echo "</div>" ;
echo '<br>';
echo '<br>';
echo '<br>';
echo "<div id='artakt'>" ;
echo "Active : ".$results['BSTHINW3']."";
echo "</div>" ;
}
}
else{
echo "Keine Ergebnisse";
}
}
else{
echo " Minimum length : ".$min_length;
}
?>
</body>
</html>
我希望有人了解我想做的事情并且能够帮助我。提前谢谢!