Jump to content

Recommended Posts

When I press any buttons to delete, add or subtracts (etc) things on my website, it always go to the top, like if it's refreshing the site.

Any idea how I can avoid this ? Is it possible overall?

 

Give us a bit more information than that, internet stranger. Is your website live? Can we have a link?

no my website is not live, but it's like.. pressing a button, and the coding i have is almost like ajax etc.. so, it refresh it self because it needs to update the php stuff within the file, BUT I need it to stay and not jump to the top ;\

Well then clearly there is something wrong with the way you've built it, but you haven't posted any code.

 

Well, here is some of the code that can be the reason?

 

if (isset ($_GET['add'])) {
$quantity = mysql_query ('SELECT id, quantity FROM products WHERE id=' .mysql_real_escape_string ((int) $_GET ['add']));
while ($quantity_row = mysql_fetch_assoc ($quantity)) {
if ($quantity_row['quantity'] !=$_SESSION['cart_'.(int)$_GET['add']])  {
 $_SESSION['cart_'.(int)$_GET['add']]+='1';

}
}
header('Location: '.$page);
}
if (isset($_GET['remove'])) {
$_SESSION['cart_'.(int)$_GET['remove']]--;
header('Location: '.$page);
}
if (isset($_GET['delete'])) {
$_SESSION['cart_'.(int)$_GET['delete']]='0';
header('Location: '.$page);
}

The <a> tag itself probably has an href="#". That will scroll to the top of the page unless the onclick of that <a> tag has return false at the end.

 

When I press a "delete, add or subtract" button, this scripts will be runned, but they do not have a "#". They do have for eksample:

<a href="cart.php?add=' .$get_row['id']. '">

You ARE refreshing the site. You're going to a whole new page. That's the problem: it's doing what you tell it to do.

 

If you'd like to perform actions WITHOUT refreshing the page, use javascript.

 

Well, with the code I have .. I think it will be pretty much I have to do different if I'm going to change to only using Javascript.. so, I hope that is not the only option?

I don't think so, considering the spelling of the word "Example".

what's that suppose to mean? >_>

I'm aware that my PHP/html (etc) skills are not far as good as you guys, but I'm here to find help.. i'm not here to be chopped at.

Also.. I'm just telling you this, it's not because i'm angry.

what's that suppose to mean? >_>

I'm aware that my PHP/html (etc) skills are not far as good as you guys, but I'm here to find help.. i'm not here to be chopped at.

Also.. I'm just telling you this, it's not because i'm angry.

 

I wasn't intentionally being a jerk, I'm sorry.

Edited by ManiacDan
language

If you don't want to refresh the page when you do something, you HAVE to use javascript. If that something requires working with PHP or MySQL, you HAVE to use AJAX.

Well it has to be php and mysql so, ajax it is.. then this problem can't really be solved? it's not a major problem realy, just something I would like to fix if it is possible.

Ok, for real, read this:

 

In order to perform an action without refreshing the page, you must use javascript.  If said action interacts with the server, you must use AJAX. 

 

Go read it again to be sure you understand it.

 

Now that you get that:  You can use named anchor tags and hash marks in your URLs so that, when you refresh the page, the page automatically scrolls back down to a specific target.  This solves what you're complaining about ("page scrolls up") without forcing you to learn and implement ajax.

Ok, for real, read this:

 

In order to perform an action without refreshing the page, you must use javascript. If said action interacts with the server, you must use AJAX.

 

Go read it again to be sure you understand it.

 

Now that you get that: You can use named anchor tags and hash marks in your URLs so that, when you refresh the page, the page automatically scrolls back down to a specific target. This solves what you're complaining about ("page scrolls up") without forcing you to learn and implement ajax.

 

Okey.. I understood it better now, but I'm not sure how to fix it as my script is like this:

 

This is mainly the parts with + and - and remove.

Tried a few things but ending up with errors, it's mostlying trying to set <a name="x"></a> and call it insted of using the $page

 

if (isset ($_GET['add'])) {
$quantity = mysql_query ('SELECT id, quantity FROM products WHERE id=' .mysql_real_escape_string ((int) $_GET ['add']));
while ($quantity_row = mysql_fetch_assoc ($quantity)) {
if ($quantity_row['quantity'] !=$_SESSION['cart_'.(int)$_GET['add']]) {
$_SESSION['cart_'.(int)$_GET['add']]+='1';

}
}
header('Location: '.$page);
}
if (isset($_GET['remove'])) {
$_SESSION['cart_'.(int)$_GET['remove']]--;
header('Location: '.$page);
}
if (isset($_GET['delete'])) {
$_SESSION['cart_'.(int)$_GET['delete']]='0';
header('Location: '.$page);
}

 

 

echo
"<p style='width:250px; float:left;'>".
					 '<table border="1" >'.'<tr>'.'<td WIDTH="250px" HEIGHT="80px" float:left; ">'.'<center>'.$get_row['name'].'<br />'.$get_row['description'].'</center>'.'</td>'.'</tr>'.'<td WIDTH="60%" HEIGHT="50px" ">'.'<center>'.' x '.$ids[$get_row['id']].' * €'.number_format ($get_row['price'],0).' = €'.number_format($sub, 0).
				 '</td>'.'</tr>'.'<tr>'.'</center>'.'<tr>'.'<td WIDTH="200px" HEIGHT="0px"'.'<center>'
 .'&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
 <a href="cart.php?remove='.$get_row['id'].'"><img src="subtract.png" border="0" style="height: 20px; width: 35px" ></a> &nbsp&nbsp

					 <a href="cart.php?add='.$get_row['id'].'"><img src="pluss.png" border="0" style="height: 20px; width: 35px" ></a> &nbsp&nbsp

					 <a href="cart.php?delete='.$get_row['id'].'"><img src="delete.png" border="0" style="height: 20px; width: 50px" ></a></p>'
 .'</center>'
 .'</td>'
 .'</tr>'

 .'</td>'.'</tr>'.'</table>';

Edited by hahaitwork
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.