|
|
|
| Вот сижу читаю PHP5 практика создания web-сайтов. Пытаюсь построить запрос аналогичный книжному (переделываю свои старые каляки-маляки)
Этот скрипт работает, но мне надо его изменить так, чтобы
if(isset($_POST['status']) && $_POST['status']!='0') $tmp2 = " and status<'".$_POST['status']."'";
if(isset($_POST['city']) && $_POST['city']!='0') $tmp1 = " and city='".$_POST['city']."'";
if(isset($_POST['location']) && $_POST['location']!='0') $tmp3 = " and location='".$_POST['location']."'";
|
то же делалась выблрка. Месагу я уже прилепила, а остальное не могу. Помогите...
<?php
if(isset($_POST['status']) && $_POST['status']!='0') $tmp2 = " and status='".$_POST['status']."'";
if(isset($_POST['city']) && $_POST['city']!='0') $tmp1 = " and city='".$_POST['city']."'";
if(isset($_POST['location']) && $_POST['location']!='0') $tmp3 = " and location='".$_POST['location']."'";
$query = "SELECT * FROM hotels
WHERE hide='show'
".$tmp1.$tmp2.$tmp3."
ORDER BY status, distance";
$hot = mysql_query($query);
if(!$hot) puterror("ERROR !");
// Смотрим сколько чего.
// Если NULL, просто выводим все относительно двух других параметров
if(mysql_num_rows($hot) == 0)
{
// Showing the message
echo("<div id=msg-error><img src=../images/icons/attantion.jpg width=18 height=16 />
<p>Sorry, but there are no ".$hot['status']." star hotels in that area of ".$_POST['city'].".</p>
<ul><li>Please, check the list of hotels that we have selected for you according your request</li></ul>
</div>");
$hotels = mysql_fetch_array($hot);
$_GET['hotel_id'] = $hotels['hotel_id'];
$_GET['hotel_name'] = $hotels['hotel_name'];
$_GET['status'] = $hotels['status'];
$_GET['photo'] = $hotels['photo'];
$_GET['country'] = $hotels['country'];
$_GET['city'] = $hotels['city'];
$_GET['address'] = $hotels['address'];
$_GET['metro'] = $hotels['metro'];
$_GET['distance'] = $hotels['distance'];
$_GET['note'] = $hotels['note'];
}
// Если больше одной - выводим список статей
else
{
while($hotels = mysql_fetch_array($hot))
{
// DO NOT EDIT BELOW !!!
// Setting a country
switch ($hotels['country'])
{
case 'russia':
$country = "Russia";
break;
}
// Setting a city
switch ($hotels['city'])
{
case 'moscow':
$city = "Moscow";
break;
case 'stpeter':
$city = "St. Petersburg";
break;
}
// Setting a hotel status
switch ($hotels['status'])
{
case '5':
$status = "images/hotels/fivestar.gif";
break;
case '4':
$status = "images/hotels/fourstar.gif";
break;
case '3':
$status = "images/hotels/threestar.gif";
break;
}
echo"<h3><a href=http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?prop_id=".$hotels['hotel_ID'].">".$hotels['hotel_name']."</a></h3>
<div class=status><img src='../$status'></div>
<div class=hotpic>
<img class=hotpic src=../".$hotels['photo'].">
<p>$country, $city, ".$hotels['address']."<br>
Nearest metro: ".$hotels['metro']."<br>
Distance: ".$hotels['distance']."<br>
Hotel Note: <a class=hotelnote>".$hotels['note']."</a><br>
<ul class=reserve>
<li class=reserve><a href=http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?prop_id=".$hotels['hotel_ID']."></a></li>
</ul></div>";
echo "<div class=reserve-button reserve><input type=image id=reserve-button src=../images/icons/learnmore.jpg></div>";
}
}
?>
|
| |
|
|
|
|
|
|
|
для: sasch
(08.06.2006 в 17:59)
| | Что, никто не знает? | |
|
|
|
|
|
|
|
для: sasch
(08.06.2006 в 18:35)
| | Вы не написали, в чем у Вас проблема. Что именно не идет.
А запустить этот пример без фрагмента дампа БД и без формы, которая создает поля - нереально.
С моей точки зрения, эту кашу легче сварить заново, чем расхлебать.
Но даже в этом случае нужна структура таблиц и фрагмент дампа БД. | |
|
|
|
|
|
|
|
для: Trianon
(08.06.2006 в 18:47)
| | А что тут вся информация есть.
Три параметра передаются из формы
if(isset($_POST['status']) && $_POST['status']!='0') $tmp2 = " and status='".$_POST['status']."'";
if(isset($_POST['city']) && $_POST['city']!='0') $tmp1 = " and city='".$_POST['city']."'";
if(isset($_POST['location']) && $_POST['location']!='0') $tmp3 = " and location='".$_POST['location']."'";
|
Надо поставить условие для вывода данных если
if(isset($_POST['status']) && $_POST['status']!='0') $tmp2 = " and status < '".$_POST['status']."'";
if(isset($_POST['city']) && $_POST['city']!='0') $tmp1 = " and city='".$_POST['city']."'";
if(isset($_POST['location']) && $_POST['location']!='0') $tmp3 = " and location='".$_POST['location']."'";
после вывода сообщения:
// Showing the message
echo("<div id=msg-error><img src=../images/icons/attantion.jpg width=18 height=16 />
<p>Sorry, but there are no ".$hot['status']." star hotels in that area of ".$_POST['city'].".</p>
<ul><li>Please, check the list of hotels that we have selected for you according your request</li></ul>
</div>");
|
Только я не знаю как...
Должно выводить
echo"<h3><a href=http://".$_SERVER['SERVER_NAME'].DIR_TO_HOTELS."?prop_id=".$hotels['hotel_ID'].">".$hotels['hotel_name']."</a></h3>
<div class=status><img src='../$status'></div>
<div class=hotpic>
<img class=hotpic src=../".$hotels['photo'].">
<p>$country, $city, ".$hotels['address']."<br>
Nearest metro: ".$hotels['metro']."<br>
Distance: ".$hotels['distance']."<br>
Hotel Note: <a class=hotelnote>".$hotels['note']."</a><br>
<ul class=reserve>
<li class=reserve><a href=http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?prop_id=".$hotels['hotel_ID']."></a></li>
</ul></div>";
echo "<div class=reserve-button reserve><input type=image id=reserve-button src=../images/icons/learnmore.jpg></div>";
|
| |
|
|
|
|
|
|
|
для: sasch
(08.06.2006 в 18:53)
| | Ребята, но помогити мне. Please. | |
|
|
|
|
|
|
|
для: sasch
(08.06.2006 в 22:09)
| | >А запустить этот пример без фрагмента дампа БД и без формы. | |
|
|
|
|
|
|
|
для: sasch
(09.06.2006 в 14:02)
| | о. ща глянем. | |
|
|
|
|
|
|
|
для: Trianon
(09.06.2006 в 14:07)
| | Хочу повториться, там все работает, но если, к примеру, я выбираю :
Moscow
Near Airports
5starts
то должно выходить и сообщение, и отели классом ниже т.к. там нет таких отелей, а предложить что-то надо.
Спасибо. | |
|
|
|
|
|
|
|
для: sasch
(09.06.2006 в 14:13)
| | Момент первый. В функции cvt явно две сорные строки - их надо удалить:
if(!is_integer(intval($y)))
return die($y) *false;
|
Момент второй. Нужно поставить строку перед строками
if(isset($_POST['status']) && $_POST['status']!='0') $tmp2 = " and status='".$_POST['status']."'";
if(isset($_POST['city']) && $_POST['city']!='0') $tmp1 = " and city='".$_POST['city']."'";
if(isset($_POST['location']) && $_POST['location']!='0') $tmp3 = " and location='".$_POST['location']."'";
|
Насчет отелей класса ниже - сейчас гляну.
Кстати, у Вас аська есть? А то, похоже, я один "заинтересованных лиц" остался. :) | |
|
|
|
|
|
|
|
для: Trianon
(09.06.2006 в 14:29)
| | Нет, аськи нет, но если надо поставлю. Какую лучше? | |
|
|
|
|
|
|
|
для: sasch
(09.06.2006 в 14:35)
| | Я тут по форуму походила и нашла ссылку на статью про сессии, что вы предложили прочитать. Очень позновательно и для меня. Очень вожно понять для чего нужны сессии. Я ими пользуюсь не так. | |
|
|
|
|
|
|
|
для: sasch
(09.06.2006 в 14:55)
| | Где новую аську можно скачать? И какая (#) новая, свежая? | |
|
|
|
|
|
|
|
для: sasch
(09.06.2006 в 15:00)
| | Нашла 5.1. Качаю. | |
|
|
|
|
|
|
|
для: sasch
(09.06.2006 в 14:13)
| |
<?php
// include 'config.inc.php'; // соединяемся с базой
$status = '3'; $tmp1 = $tmp2 = $tmp3 = '';
if(isset($_POST['status']) && $_POST['status']!='0') $tmp2 = " and status='".($status=$_POST['status'])."'" ;
if(isset($_POST['city']) && $_POST['city']!='0') $tmp1 = " and city='".$_POST['city']."'";
if(isset($_POST['location']) && $_POST['location']!='0') $tmp3 = " and location='".$_POST['location']."'";
$query = "SELECT * FROM hotels
WHERE hide='show'
".$tmp1.$tmp2.$tmp3."
ORDER BY status, distance";
$hot = mysql_query($query);
if(!$hot) puterror("ERROR !");
// Смотрим сколько чего.
// Если NULL, просто выводим все относительно двух других параметров
while($status != '3' && mysql_num_rows($hot) == 0 )
{
$status = $status - 1;
$tmp2 = " and status='$status'";
$query = "SELECT * FROM hotels
WHERE hide='show'".$tmp1.$tmp2.$tmp3."
ORDER BY status, distance";
$hot = mysql_query($query);
if(!$hot) puterror("ERROR !");
$status = - $status;
}
// Showing the message
if(mysql_num_rows($hot) == 0)
{
echo("<div id=msg-error><img src=../images/icons/attantion.jpg width=18 height=16 />
<p>Sorry, but there are no ".$_POST['status']." star hotels in that area of ".$_POST['city'].".</p>
<ul><li>Please, check the list of hotels that we have selected for you according your request</li></ul>
</div>");
}
// Если больше одной - выводим список статей
else
{
if($status < 0)
{
$status = - $status;
echo "-------------- hotel status reduced to $status-stars -------";
}
while($hotels = mysql_fetch_array($hot))
{
// DO NOT EDIT BELOW !!!
// Setting a country
|
и далее по тексту | |
|
|
|
|
|
|
|
для: Trianon
(09.06.2006 в 15:08)
| | При обращении к другим отелям - ошибка.
Parse error: parse error, unexpected T_ELSE in z:\home\localhost\www\hotels\searcher.php on line 29
|
| |
|
|
|
|
|
|
|
для: sasch
(09.06.2006 в 15:58)
| | Нет, это моя ошибка. Все работает. Спасибо. | |
|
|
|
|
|
|
|
для: sasch
(09.06.2006 в 15:58)
| |
Слегка ошибся:
// Смотрим сколько чего.
// Если NULL, просто выводим все относительно двух других параметров
if($status != '3' && mysql_num_rows($hot) == 0)
{
while($status != '3' && mysql_num_rows($hot) == 0 )
{
$status = $status - 1;
$tmp2 = " and status='$status'";
$query = "SELECT * FROM hotels
WHERE hide='show'".$tmp1.$tmp2.$tmp3."
ORDER BY status, distance";
$hot = mysql_query($query);
if(!$hot) puterror("ERROR !");
}
$status = - $status;
}
// Showing the message
|
| |
|
|
|
|
|
|
|
для: Trianon
(09.06.2006 в 16:08)
| | ICQ 238-256-091 | |
|
|
|