| |
|
|
| | Здравствуйте
У меня на сайте форма по двум параметрам:
а. формат материала: 10x10, 20x20, 30x30...
b. цвет материала: красный, желтый, белый, ....
как можно узнать по каким параметрам сколько раз искали материал?
Как это осуществить?
Может ли кто-нибудь скинуть пример программки на php?
Спасибо | |
| |
|
|
| |
|
|
| |
для: anton2106
(04.11.2006 в 14:22)
| | | Нужно больше подробностей. Где хранится информация? В статических HTML-файлах или в базе данных? | |
| |
|
|
| |
|
|
| |
для: cheops
(04.11.2006 в 14:57)
| | | а нигде не хранится
в зависимости от выбранных значений загружается соотв файл, т.е. if d=10x10 include.... | |
| |
|
|
| |
|
|
| |
для: anton2106
(04.11.2006 в 15:14)
| | | Так, вот код:
<?
$format = $_POST['format'];
$color = $_POST['color'];
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" style="width: 60%;">
<fieldset>
<legend>Choose format</legend>
<input name="format" id="format1" type="radio" value="10"<? if ($format == '10') print ' checked="checked"';?> /><LABEL for="format1">10x10</LABEL><BR />
<input name="format" id="format2" type="radio" value="20"<? if ($format == '20') print ' checked="checked"';?> /><LABEL for="format2">20x20</LABEL><BR />
<input name="format" id="format3" type="radio" value="30"<? if ($format == '30') print ' checked="checked"';?> /><LABEL for="format3">30x30</LABEL><BR />
</fieldset>
<fieldset>
<legend>Choose color</legend>
<input name="color" id="color1" type="radio" value="red" checked="checked"<? if ($color == 'red') print ' checked="checked"';?> /><LABEL for="color1">red</LABEL><BR />
<input name="color" id="color2" type="radio" value="yellow"<? if ($color == 'yellow') print ' checked="checked"';?> /><LABEL for="color2">yellow</LABEL><BR />
<input name="color" id="color3" type="radio" value="white"<? if ($color == 'white') print ' checked="checked"';?> /><LABEL for="color3">white</LABEL><BR />
</fieldset>
<fieldset style="text-align: center;">
<legend>What to do next?</legend>
<input type="submit" value="Find" /><input type="reset" value="reset" />
</fieldset>
</form>
<?
if ($format && $color)
{
// find
echo "something founding...<BR />";
switch ($format)
{
case '20': $format_sel = 2; break;
case '30': $format_sel = 3; break;
default: $format_sel = 1;
}
switch ($color)
{
case 'yellow': $color_sel = 2; break;
case 'white': $color_sel = 3; break;
default: $color_sel = 1;
}
$file = "stat.dat";
$stat = file($file);
$stat[$format_sel - 1] = $stat[$format_sel - 1] + 1;
$stat[2 + $color_sel] = $stat[2 + $color_sel] + 1;
$data = '';
$i = 0;
for (; $i < count($stat); $i ++)
$data .= str_replace("\n","",$stat[$i])."\n";
file_put_contents($file, $data); // only if PHP is more then 5th version!
$stat = file($file);
$my = array ('10x10','20x20', '30x30', 'red', 'yellow', 'white');
for ($i = 0; $i < count($stat); $i ++)
echo $my[$i].": ".$stat[$i]."<BR />";
}
?>
|
я думаю, ниче шо на англ, его ж тут все должны знать. :))
Сохраняешь его в ПХП файл.
и создаешь в той же директории файл "stat.dat" где пишешь:
А теперь запускай, тестирую! У меня все работало!
Конечно метод с файлами - не лучший, но это лучше чем ничего! ;)
З.Ы. А вообще основной код есть в прикрепленном файле, только останется файлик с данными создать! | |
| |
|
|
| |
|
|
| |
для: ihoru
(04.11.2006 в 15:22)
| | | создал файл test.php с вашим кодом (полностю скопировал)
создал файл в блокноте stat.dat записал шесть нулей
открыл страницу с формой
пару раз повыбирал формат
ничего в файле dat не меняется | |
| |
|
|
| |
|
|
| |
для: cheops
(04.11.2006 в 14:57)
| | | а это зачем?
if ($format && $color)
{
// find
echo "something founding...<BR />";
switch ($format)
{
case '20': $format_sel = 2; break;
case '30': $format_sel = 3; break;
default: $format_sel = 1;
}
switch ($color)
{
case 'yellow': $color_sel = 2; break;
case 'white': $color_sel = 3; break;
default: $color_sel = 1;
} | |
| |
|
|
| |
|
|
| |
для: anton2106
(04.11.2006 в 15:54)
| | | потому что это и есть основная часть - движок так называемый!
А вообще именно эта часть для определения, какому элеименту добавлять "балл".
Так у тебя работает? | |
| |
|
|
| |
|
|
| |
для: ihoru
(04.11.2006 в 16:08)
| | | нет, смотри ответ выше) | |
| |
|
|
| |
|
|
| |
для: anton2106
(04.11.2006 в 16:10)
| | | Наверно не выставили права на запись в *dat | |
| |
|
|
| |
|
|
| |
для: EXP
(04.11.2006 в 19:48)
| | | как их сделать?
в командной строке коммандера что написать напомни пожалуйста
хотя, нет, вот "изменить атрибуты файла"
я изменил, везде галочки поставил, все равно не работает | |
| |
|
|
| |
|
|
| |
для: anton2106
(04.11.2006 в 19:55)
| | | Скорей всего у вас стоит не пятая версия ПХП, я ж коментарием писал, что ф. file_put_contents - только начиная с пятого ПХП.
Но можно записывать и по-другому, обычным методом:
вместо:
file_put_contents($file, $data);
пишете вот это:
$f = fopen($file, "w");
fwrite($f,$data);
fclose($f);
// если я вдруг ошибся, то извените, писал по памяти не тестирую
|
Пробуй теперь! | |
| |
|
|
| |
|
|
| |
для: ihoru
(04.11.2006 в 23:18)
| | | спасибо
работает
посмотри http://www.postavkin.spb.ru/poisk/test.php
только если не сложно скажи как сделать так что бы на страницу это добро не выводилось | |
| |
|
|
| |
|
|
| |
для: anton2106
(05.11.2006 в 20:52)
| | | Легко! :)
Убрать последние гтри строчки:
$my = array ('10x10','20x20', '30x30', 'red', 'yellow', 'white');
for ($i = 0; $i < count($stat); $i ++)
echo $my[$i].": ".$stat[$i]."<BR />";
|
- эти, просто надо ж было тебе как-то показать, что все работает! :)
Ну, а где-то ж тебе все равно это надо будет смотреть?
А еще убери эти две строки:
// find
echo "something founding...<BR />";
|
А ты заметил, что стандартно "color" - выбрано, а "format" - нет!
аа... это я там ошибку допустил!
мцаа...
замени вот этот блок (всю форму):
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" style="width: 60%;">
<fieldset>
<legend>Choose format</legend>
<input name="format" id="format1" type="radio" value="10"<? if ($format == '10') print ' checked="checked"';?> /><LABEL for="format1">10x10</LABEL><BR />
<input name="format" id="format2" type="radio" value="20"<? if ($format == '20') print ' checked="checked"';?> /><LABEL for="format2">20x20</LABEL><BR />
<input name="format" id="format3" type="radio" value="30"<? if ($format == '30') print ' checked="checked"';?> /><LABEL for="format3">30x30</LABEL><BR />
</fieldset>
<fieldset>
<legend>Choose color</legend>
<input name="color" id="color1" type="radio" value="red" checked="checked"<? if ($color == 'red') print ' checked="checked"';?> /><LABEL for="color1">red</LABEL><BR />
<input name="color" id="color2" type="radio" value="yellow"<? if ($color == 'yellow') print ' checked="checked"';?> /><LABEL for="color2">yellow</LABEL><BR />
<input name="color" id="color3" type="radio" value="white"<? if ($color == 'white') print ' checked="checked"';?> /><LABEL for="color3">white</LABEL><BR />
</fieldset>
<fieldset style="text-align: center;">
<legend>What to do next?</legend>
<input type="submit" value="Find" /><input type="reset" value="reset" />
</fieldset>
</form>
|
На:
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" style="width: 60%;">
<fieldset>
<legend>Choose format</legend>
<input name="format" id="format1" type="radio" value="10"<? if (($format != '20') && ($format != '30')) print ' checked="checked"';?> /><LABEL for="format1">10x10</LABEL><BR />
<input name="format" id="format2" type="radio" value="20"<? if ($format == '20') print ' checked="checked"';?> /><LABEL for="format2">20x20</LABEL><BR />
<input name="format" id="format3" type="radio" value="30"<? if ($format == '30') print ' checked="checked"';?> /><LABEL for="format3">30x30</LABEL><BR />
</fieldset>
<fieldset>
<legend>Choose color</legend>
<input name="color" id="color1" type="radio" value="red"<? if (($color != 'yellow') && ($color != 'white')) print ' checked="checked"';?> /><LABEL for="color1">red</LABEL><BR />
<input name="color" id="color2" type="radio" value="yellow"<? if ($color == 'yellow') print ' checked="checked"';?> /><LABEL for="color2">yellow</LABEL><BR />
<input name="color" id="color3" type="radio" value="white"<? if ($color == 'white') print ' checked="checked"';?> /><LABEL for="color3">white</LABEL><BR />
</fieldset>
<fieldset style="text-align: center;">
<legend>What to do next?</legend>
<input type="submit" value="Find" /><input type="reset" value="reset" />
</fieldset>
</form>
|
Щас должно нормально выделять и не повторяться дважды выделение, как раньше...
Вобщем, если что стучи: 226-546-204 | |
| |
|
|
| |
|
|
| |
для: ihoru
(05.11.2006 в 22:17)
| | | переделал под свой сайт
http://www.postavkin.spb.ru/poisk/test2.php
иногда почему то вместо вариантов в списке появляются какие то кракозябры...
может потому что в списке вариантов есть записи на русском языке? | |
| |
|
|