Jump to content

Deleting echo'd mysql results from a html page using PHP


Ulterior

Recommended Posts

Ok I have a products page which querys using php to a mysql database and echo's the results to a page. I want to be able to have seperate products lists, so that I can click a button on the side and have it delete/hide what was already echo'ed there and fetch the new rows, Either a button or a drop down list. But I don't know much of PHP at all, and don't know if there's a way to hide or delete an result from mysql using php. Or to create a certain 'function'? in php that can be toggled in javascript? Anyways enough of me attempting to explain it I'll just post the code up: <?php $result = mysql_query("SELECT * FROM internet_shop");while($row=mysql_fetch_assoc($result)){echo '<div class="product"><img src="img/products/'.$row['img'].'" alt="'.htmlspecialchars($row['name']).'" width="128" height="128" class="pngfix" /></div>';} ?> Any other code you need to see I'd be happy to paste up here.

Link to comment
Share on other sites

It's not simple. You would need to use Javascript to perform an HTTP request using AJAX. PHP does not execute anymore after the page has finished loading.

Link to comment
Share on other sites

Oh ok, so It's probably not worth looking to do it that way until i get decent with Ajax, PHP and Javascript. Is there another way I can get many products displaying on one page that's a little easier?

Link to comment
Share on other sites

Have a query string on the URL that tells PHP which things to display. Then just print out links to the pages. It will cause the page to reload with the new content.

Link to comment
Share on other sites

Not sure I understand. So I could have a button('s) next to the products content div, and on click just have them reload the page with different mysql databases?

Link to comment
Share on other sites

Hmm... It's a bit complicated to explain from the very beginning. You have a link to a page: product.php?data=somethingIn PHP, you can choose what to load based on the value of data:

if($_GET['data'] == 'something') {	// perform a query and show the data} else if($_GET['data'] == 'something_else') {	// Load differend data from the database}

Link to comment
Share on other sites

But technically that'd be the same as just copying out product.php for instance, however many times to create a bunch of new pages and just switching out the database loaded from with another? Or am I misunderstanding you? I don't want to have 60 different pages for different products really, want a decent way it can be displayed on a few or one page if needs be.

Link to comment
Share on other sites

Ok so would you be able to get that single file to load a different database depending on which button was clicked? Thanks for the link I'll check it out, as I think I still don't fully understand this.

Link to comment
Share on other sites

If the products in the database have an ID, you can load them by passing the ID to the query.Here's a simple example:

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;$query = mysql_query("SELECT * FROM products WHERE id={$id}");

Link to comment
Share on other sites

Ok cool, thanks for that bit of code. I'm gonna try to learn some php, what's the best way in your opinion to learn php? One other thing, I have a shopping cart which you can drag products into, I want to try to turn that into an enquiry form so that when the email is sent the products go with it. Right now it's just a shopping cart with a checkout that goes to a separate page, this is 'Tutorialzines demo' btw don't know if you heard of it. So yeah, is that still too ambitious for me? ;p

Edited by Ulterior
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...