Answer the question
In order to leave comments, you need to log in
What is the correct way to use a cycle?
Good day.
There are goods, they are in the MySql database. There are also divs with different classes. They need to put the goods that I take from the database.
How can I make it loop so that each product goes into these divs. Here's what I roughly mean:
$result = mysql_query("SELECT * FROM `catalog` WHERE `type`='$_GET[type]' ORDER BY `id` DESC");
$res = array();
// знаю, что $_GET нужно обрабатывать, это просто пример
<div class="item active">Товар 1</div>
<div class="item active big">Товар 2</div>
<div class="item active">Товар 3</div>
<div class="item active right">Товар 4</div>
<div class="item active margin-top-500">Товар 5</div>
Answer the question
In order to leave comments, you need to log in
Starting from the 3rd version, the signature of the constructor has changed. Either rollback to previous versions, or change the code to something like:
FirebaseListOptions<Message> options =
new FirebaseListOptions.Builder<Message>()
.setQuery(mDatabase.child("chat"), Message.class)
.setLayout(R.layout.item)
.build();
adapter = new FirebaseListAdapter<Message>(options) {
...
I could be wrong, but my first argument is that you put this ---> com.example.parallax.Game.Chat in there, and the constructor expects com.example.parallax.Game.Message
You should not immediately write a certain number of elements, and then stuff the result into them. No.
You should in a loop immediately display the markup into which you insert data. How many iterations the loop will make - exactly so many tags will be eaten out.
The example below is terrible, but it gets the point across.)
$result = mysql_query("SELECT * FROM `catalog` WHERE `type`='$_GET[type]' ORDER BY `id` DESC");
while($row = mysql_fetch_assoc($result)){
echo "<div class=\"item active\">".$row["name"]."</div>";
}
If these classes are not data dependent, use the nth-child selector in css instead
Better use PDO.
<?php
# подключаемся к базе данных
try {
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}catch(PDOException $e) {
echo "Хьюстон, у нас проблемы.";
}
# данные, которые мы вставляем
$data = [
'type' => $_GET['type']
];
# делаем запрос
$STH = $DBH->prepare("select * from catalog where catalog.type = :type order by catalog.id desc");
$STH->execute($data);
# устанавливаем режим выборки
$STH->setFetchMode(PDO::FETCH_ASSOC);
# выводим результат
while($row = $STH->fetch()) {
echo "<div class=\"item active\">{$row['name']} - {$row['price']}</div>";
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question