Click here to Skip to main content
16,005,389 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi So at the moment, i have a max of 4 items showing.

When user clicks a button, i want that item to be replaced with another item?

I have tried extending the count which does work but is there any way i can actually replace that selected one with that item?

see code below.

What I have tried:

$cnt=0;
$max=4;


$Displayed=false;
$inserted=false;


while($dbRow=$dbQuery->fetch(PDO::FETCH_ASSOC) and ($cnt < $max))  
 {		
   echo "".$dbRow["Name"]."</h4><br>"."<br><img src=/".$dbRow['Picture']."'width='150' height='150' />"."<br><br>".$dbRow["Instructions"]."
			

<form method='POST'><input type='hidden' name='MealID' value= '".$dbRow['MealID']."'>
<input type='submit' name='submit' value='Complete'></form>";
	
			
$cnt++;
if(($_POST['MealID'])) {
	$max=5;
}
Posted
Updated 5-Apr-18 5:14am

1 solution

Best way to replace things on a web page is AJAX[^]

All of your items must have an id='' to be targeted by AJAX

You don't use a form - you send the data to the server and it sends data back to the page - which then updates the targeted item.

AJAX is invoked in a javaScript - but the link I supplied will give you a boiler-plate level example and you only need to change it to match your page's data and control ID's. The PHP on the server side does work - returns data - but doesn't replace your page as would a <form> - for most things, this is far superior to forms for changing data viewed by the user.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900