first let me say that i'm pretty much new to PHP. Im having fun trying it out and learning it! Now I ran into something that is out of my league.
What Im trying to do is : only return the results where there is an X in a certain column.
The Screenshot is partly in german but i will explain :
What it looks like
Currently I have 2 search forms. My code is probably pretty bad or can be made way simpler.. I just dont know how. The problem is most of it is in 1 table and 1 part in a different table.
Now I want to have it where if I search a product, it should only put out the products where there is an X in the column 'BSTHINW3'
The 2 scripts I use to make it possible right now :
<?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>
I hope someone understands what Im trying to do and is able to help me out. Thanks in advance!