Вот страница, на которой размещено порядка сотни элементов, это игра и я в ней сажаю и поливаю деревья, собираю урожай.
На каждом дереве есть кнопка "Собрать урожай" или "Удобрить" или "Полить"
Так вот, очень неудобно скроллить вниз страницы, нажать на одном дереве "Собрать урожай" и страница опять ползёт вверх, вернее перезагружается после записи значений в БД.
Мои попытки попытки работы с javascript привели к дублированию информации в БД, а страница всё-равно перезагружалась.
Убрал всё что наделал и решил показать профессионалам- обьясните общий подход- где куда вставлять нужно - а то я не по тому пути пошёл наверно. Знаний в этой области 0.
<?
if(isset($_GET['gos']))
{
if(isset($mc))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_plant` WHERE `id` = '$gos[id_plant]' AND (`level` = '$ku[level]' OR `level` < '$ku[level]')"),0)!=0)
mysql_query("UPDATE `kolhoz_user` SET `last_plant` = '$gos[id_plant]' WHERE `id` = '$ku[id]'");
header("Location:?myfarm");
exit;
}
else err_game("Для начала вступите в колхоз.");
}
?>
<table width="700" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="tab1">
<table class="zag_page" align="center">
<tbody>
<tr>
<td width="60" valign="middle" align="center"> </td>
<td align="center" valign="middle">Грядки</td>
<td width="60" valign="middle" align="center"><a href="?myfarm&reflesh=<?=rand(99999,99999999);?>"><img title="Обновить" class="imgob" width="25" height="25" src="img/refresh.png" alt="i"></a></td>
</tr></tbody></table></td></tr>
<td class="tab2"><div class="block_tab">
<?
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_ground` WHERE `id_user` = '$ku[id]' AND (`time` < '$time' OR `time` = '$time') AND `id_plant` != '0'"),0)!=0 && $ku['harvester']>0)echo "<div><img width='16' height='16' src='images/icons/harvest.png' alt='o'> <a class='dt-sc-button small theme-btn' href='?myfarm&harvest_all'>Собрать все</a></div>";
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_ground` WHERE `id_user` = '$ku[id]' AND `soil` = '0' AND (`time_soil` = '$time' OR `time_soil` < '$time') AND `id_plant` != '0' AND `time` > '$time'"),0)!=0 && $ku['soiler']>0)echo "<div><img width='16' height='16' src='images/icons/soil.png' alt='o'> <a class='dt-sc-button small theme-btn' href='?myfarm&soil_all'>Удобрить все</a></div>";
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_ground` WHERE `id_user` = '$ku[id]' AND `id_plant` != '0' AND (`time_water` = '$time' OR `time_water` < '$time') AND `time` > '$time' AND (`soil` = '0' AND `time_soil` > '$time' OR `soil` = '1')"),0)!=0 && $ku['irregate']>0)echo "<div><img width='16' height='16' src='images/icons/water.png' alt='o'> <a class='dt-sc-button small theme-btn' href='?myfarm&water_all'>Полить все</a></div>";
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_ground` WHERE `id_user` = '$ku[id]' AND `id_plant` = '0' AND `cultivator` = '1'"),0)!=0 && $ku['seeder']>0)echo "<div><img width='16' height='16' src='images/icons/seat.png' alt='o'> <a class='dt-sc-button small theme-btn' href='?myfarm&seat_all'>Засеять все</a></div>";
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_ground` WHERE `id_user` = '$ku[id]' AND `id_plant` = '0' AND (`time` = '$time' OR `time` < '$time') AND `cultivator` = '0'"),0)!=0 && $ku['cultivator']>0)echo "<div><img width='16' height='16' src='images/icons/dig.png' alt='o'> <a class='dt-sc-button small theme-btn' href='?myfarm&cultivator_all'>Вскопать все</a></div>";
////ГРЯДКИ
if($ku['last_plant']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_plant` WHERE `id` = '$ku[last_plant]'"),0)!=0)$lp=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant` WHERE `id` = '$ku[last_plant]'"));
if($ku['last_soil']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_soil` WHERE `id` = '$ku[last_soil]'"),0)!=0)$ls=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_soil` WHERE `id` = '$ku[last_soil]'"));
?>
<img width='14' height='14' src='images/icons/seat.png' alt='i' class='imgp'> <a class='link_m' href='?myfarm&change_plant'>Выбрать семена</a>: <span class='text'><?=(isset($lp)?"".hsc($lp['name'])."":"-");?></span><br>
<img width='14' height='14' src='images/icons/soil.png' alt='i' class='imgp'> <a class='link_m' href='?myfarm&change_soil'>Выбрать удобрение</a>: <span class='text'><?=(isset($ls)?"".hsc($ls['name'])."":"-");?></span><br>
<?
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_ground` WHERE `id_user` = '$ku[id]'"),0);
if ($k_post==0)
{
echo "Список пуст...";
}
$k_page=k_page($k_post,5);
$page=page($k_page);
$start=5*$page-5;
$q=mysql_query("SELECT * FROM `kolhoz_ground` WHERE `id_user` = '$ku[id]' ORDER BY `id`");
while($post=mysql_fetch_array($q))
{
?>
<?
if($post['id_plant']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_plant` WHERE `id` = '$post[id_plant]'"),0)!=0)$plant=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant` WHERE `id` = '$post[id_plant]'"));
echo "<table class='block_tab_plant'><tbody><tr><td align='center' width='150'>
<img class='img_grjdki' width='80' height='50' src='".(!isset($plant)?"".($post['cultivator']==1?"images/pole2.png":"images/pole.png")."":"images/plants/$plant[id].png")."' alt='o' class='portrait'>";
echo "<tr height='40'><td align='center' valign='middle'>".(!isset($plant)?"<span class='title'>".($post['cultivator']==1?"Земля, готовая к посеву":"Необработанная земля")."</span>":"<span class='text_z'>".hsc($plant['name'])."</span>".($post['time']>$time?"<span class='small minor'><br> <span class='text_gr'> ".time_left($post['time']-$time)."</span></span>":null)."")."</td></tr>";
if(isset($plant))
{
if($post['time']<=$time)
{
echo "<tr height='40'><td align='center' valign='middle'><a href=?myfarm&harvest=$post[id]><input type='submit' value='Собрать урожай' class='btn_small'></td></tr>";
}
else
{
if($ku['last_soil']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_soil` WHERE `id` = '$ku[last_soil]'"),0)!=0)
$ls=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_soil` WHERE `id` = '$ku[last_soil]'"));
echo "<tr height='40'><td align='center' valign='middle'>".($post['time_soil']<=$time && $post['soil']==0 && $post['time']>$time?"".(isset($ls)?"<a href='?myfarm&soil=$post[id]&select=$ls[id]'><center><input type='submit' value='Удобрить' class='btn_small'></a>":"<a href='?myfarm&soil=$post[id]'>Удобрить</a>")."":"".($post['soil']==0 && $post['time']>$time?"Удобрение через <br> <span class='text_gr'>".time_left($post['time_soil']-$time)."":null)."</span>")."</td></tr>";
}
}
else
{
if($ku['last_plant']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_plant` WHERE `id` = '$ku[last_plant]'"),0)!=0)$lp=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant` WHERE `id` = '$ku[last_plant]'"));
echo "<tr height='40'><td align='center' valign='middle'>".($post['cultivator']==1?"".(isset($lp)?"<center><a href='?myfarm&seat=$post[id]&select=$lp[id]'><span style='title'><input type='submit' value='Посадить' class='btn_small'></span></a>":"<center><a href='?myfarm&seat=$post[id]'><span style='title'><input type='submit' value='Посадить' class='btn_small'></span></a>")."":"<center><a href='?myfarm&cultivator=$post[id]'><span style='title'><input type='submit' value='Вскопать' class='btn_small'></span></a>")."";
echo "</td></tr>";
}
if(isset($plant))unset($plant);
echo "</td></tr></tbody></table>";
echo "";
}
<td align='center' valign='middle' width='110'><a class='btn_small' href='?myfarm&new_ground'>
<img width='14' height='14' src='images/icons/cart.png' alt='i' class='imgp'> Купить</a></td>";
echo "</tr></tbody></table>";
echo "</div></td>
<tr><td class='tab3'></td></tr></tbody></table>";
include_once 'inc/foot.php';
?>
<table border="0" align="center" width="580"><tbody><tr><td><table class="block_tab_plant" width="158" height="150"><tbody><tr><td align="center" width="150"><img class="img_grjdki" width="80" height="55" src="images/plants/1.png" alt="i"></td></tr><tr height="40"><td align="center" valign="middle"><span class="text_z">Пшеница</span></td></tr><tr height="40"><td align="center" valign="middle"><form action="" method="post" id="form3"><input type="hidden" name="harvest" value="235"><input type="submit" value="Собрать урожай" class="btn_small"></form></td></tr></tbody></table></td></tr></tbody></table>