Код: Выделить всё
$sql = "SELECT name, price, id, mark, value, url FROM cpu";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "CPUPriceMarkValueImage";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "[url=https://au.pcpartpicker.com/product/]" . $row["name"]. "[/url]" . $row["price"]."" . $row["mark"]."" . $row["value"]."
[img]. $row[[/img]
";
}
echo "";
} else {
echo "0 results";
}
На веб -странице у меня также есть два блока HTML ввода, одно для поиска и одно для цены:
Код: Выделить всё
Для фильтрации поиска я использую следующий код Javascript:
Код: Выделить всё
function myFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("mySearch");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
< /code>
Однако я не уверен в коде, который должен использовать для Myprice. Я считаю, что сначала я должен преобразовать столбец цены в строку, а затем выполнить фильтр. Я не уверен в точном коде, но сумел найти это, который казался похожим.var price = str.slice(1,5);
var price = parseFloat(price)
Код: Выделить всё
function myPriceFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myPrice");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
td = td.slice(1,5);
td = parseFloat(td)
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
Код: Выделить всё
function myPriceFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myPrice");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
priceLow = input * 0.9
priceHigh = input * 1.1
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
td = td.slice(1,5);
td = parseFloat(td)
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > priceLow and txtValue.toUpperCase().indexOf(filter) < priceHigh ) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/538 ... javascript
Мобильная версия