everybody. I've got a problem with creating and comparing data from database (about cars). So, what i want to make:
We have an index.php, which forms a list of cars (each one has parametres), and we put nearby a checkbox with unique id (car_short) of car, then we have to choose only two cars and when two have been already checked - block all unchecked boxes untill one of the chosen won't be unchecked, and then submit. After clicking the button, we should transmit to list.php two chosen 'car_short'. And all that is the main thing i can't understand how to make.
here's the current index.php (currently transmits last checked car in list)
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "jdmdb";
?>
<html>
<head>
<meta http-equiv="Content-Tуpe" сontent="tехt/html; charset=utf-8">
<title>JDM Database</title>
</head>
<body>
<?
$con = mysqli_connect($hostname, $username, $password) or die(mysqli_error());
$con->query("SET NAMES cp1251");
$con->select_db($dbname);
$result = mysqli_query($con, 'select * from cars') or die(mysqli_error($con));
$rows = $result->fetch_all(MYSQLI_ASSOC);
?>
<form name=carlist action="list.php" method="post">
<?
foreach ($rows as $row) {
echo '<input type=checkbox name="car_short" value="'.$row['car_short'].'"> '.$row['brand'].' '.$row['model'].' '.$row['spec'].' ('.$row['year'].')<br/>';
}
echo '<input type=submit value=123>';
?>
</form>
<?
mysqli_close($con);
?>
</body>
</html>
list.php
in second php-file, i don't understand, how to create two arrays of parameters (currently displays doubled data of last chosen car)
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "jdmdb";
function transcode(){
mb_internal_encoding("utf-8");
mb_http_output("cp1251");
ob_start("mb_output_handler");
}
?>
<html>
<head>
<meta http-equiv="Content-Tуpe" сontent="tехt/html; charset=utf-8">
<title>JDM Database</title>
</head>
<body>
<?
$con = mysqli_connect($hostname, $username, $password) or die(mysqli_error());
$con->select_db($dbname);
$result = mysqli_query($con, 'select * from cars where car_short="'.$_POST['car_short'].'" or car_short="'.$_POST['car_short'].'"') or die(mysqli_error($con));
$rows = $result->fetch_all(MYSQLI_ASSOC);
?>
<form name=carlist>
<table>
<?
foreach ($rows as $row) {
transcode();
$con->query("SET NAMES cp1251");
echo '<tr><td>Марка</td><td>'.$row['brand'].'</td><td>'.$row['brand'].'</td></tr>';
echo '<tr><td>Модель</td><td>'.$row['model'].'</td><td>'.$row['model'].'</td></tr>';
echo '<tr><td>Комплектация</td><td>'.$row['spec'].'</td><td>'.$row['model'].'</td></tr>';
echo '<tr><td>Кузов</td><td>'.$row['body'].'</td><td>'.$row['body'].'</td></tr>';
echo '<tr><td>Год выпуска</td><td>'.$row['year'].'</td><td>'.$row['year'].'</td></tr>';
echo '<tr><td>Двигатель</td><td>'.$row['engine'].'</td><td>'.$row['engine'].'</td></tr>';
echo '<tr><td>Объём двигателя</td><td>'.$row['eng_vol'].'</td><td>'.$row['eng_vol'].'</td></tr>';
echo '<tr><td>Тип двигателя</td><td>'.$row['eng_type'].'</td><td>'.$row['eng_type'].'</td></tr>';
echo '<tr><td>Тип ГРМ</td><td>'.$row['eng_valvetrain'].'</td><td>'.$row['eng_valvetrain'].'</td></tr>';
echo '<tr><td>Тип наддува</td><td>'.$row['intake_type'].'</td><td>'.$row['intake_type'].'</td></tr>';
echo '<tr><td>Турбина</td><td>'.$row['turbine'].'</td><td>'.$row['turbine'].'</td></tr>';
echo '<tr><td>Мощность двигателя</td><td>'.$row['power'].'</td><td>'.$row['power'].'</td></tr>';
echo '<tr><td>Максимальная скорость</td><td>'.$row['maxspd'].'</td><td>'.$row['maxspd'].'</td></tr>';
echo '<tr><td>Разгон от 0 до 100км/ч</td><td>'.$row['accel'].'</td><td>'.$row['accel'].'</td></tr>';
echo '<tr><td>Сухой вес, кг</td><td>'.$row['weight'].'</td><td>'.$row['weight'].'</td></tr>';
echo '<tr><td>Объём бака</td><td>'.$row['tankvol'].'</td><td>'.$row['tankvol'].'</td></tr>';
echo '<tr><td>Привод</td><td>'.$row['layout'].'</td><td>'.$row['layout'].'</td></tr>';
}
?>
</form>
<?
mysqli_close($con);
?>
</body>
</html>
here's screenshot
Any suggestion?
Aucun commentaire:
Enregistrer un commentaire