Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm having multiple images (all which are clickable and have a value associated with each) on a page. Now I want to click any of the images (representing images) and that value is stored in array. So lets say I choose image of drink then meal then extras so everytime I choose one, it is updated in array as element. I am planning to do this in PHP so i was thinking something like PHP self submit? any illustrations are helpful...
Each time I add an item, I need a counter on the same page to increase/increment...
Thanks in advance and appreciated
You'll have to use a very little bit of Javascript there, give the images an onclick-tag with an redirection or bind an event via jQuery. If you're experienced with jQuery use that otherwise use the onlick tag to append the id of your image.
example:
<img src="picture.png" onclick="window.location = 'index.php?meal=1';" />
You have to echo the id's in PHP of course.
You cannot do that only with PHP, as PHP is only executed before the page is shown.. You need to use Javascript and maybe AJAX to update your data on your back end.
Your best option is to add those highlighted items in Javascript and then send it via AJAX to your php handler.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
so I am working on a small ecommerce site and I've been stuck on this section of my site for quite a while now and can't really wrap my head around it.
I have divided the site into 3 columns with bootstrap's grid system, in the main section I have my featured products, however, I'd like everything to be dynamic, when I click on a modal with "View details" for the product the only code that works is the dynamic one, I'd like to know how to make it so that it pulls the data directly from my database, unfortunately out of frustration I deleted the little work I had done on it and can't show stick it on here so that anyone can correct it for me.
Could anyone please help me out?
Thanks!
There are many ways you could go about doing this. Here is an approach you could use:
Get the id from data attribute of your product (make sure you load it into the html).
Send a $.get request with jquery for this id to the server.
Get the data needed from the db using this id.
Render the data server side
Return html
In the callback function of your get request put the HTML into your bootstrap modal body.
Show the modal to the user.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Let's say hypothetically that I have a Div that contains the background color 'red' and I would like the user to input into a separate input box to the side of the div what color he would like this box to be changed to. How would I go about allowing this type of functionality through php so that the color chosen (and not the default 'red') remains as the color once the user has left the webpage and another has logged on?
Basically how can I allow the users choice to be final so that users can see this afterwards?
Thanks in advance!
You cannot do it on a client side. The HTML code should be generated on a server side and along with addition to DOM, AJAX call should be made to server-side script to include new elements in subsequent generations.
And you should also provide some sort of authorisation, or else your website will be full of Viagra and Forex links in no time...
You have to send the number of appended items back to the server and the server has to store that number in a database. Then, the next time the page is requested, the server can either render them or it can send the information to the client and the client can render it.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to create a page with an AJAX style form. Where on submit, the values in the form search and query a database and output the search results into the same DIV as the form was.
Any help would be much appreciated.
Thanks
jQuery is probably what you're looking for...
The docs are straightforward. http://jquery.com/
Generally, jQuery follows the find something then do something approach.
Find something ---> watch for some action on some element (in your
case, clicking submit)
Do something ---> make an ajax call to the php page you want to run
the query and return the results then insert the results where you
want on the page
http://api.jquery.com/jQuery.post/
Some other helpful jQuery commands for this task could be...
http://api.jquery.com/appendTo/
http://api.jquery.com/remove/
http://api.jquery.com/append/
Hope this helps.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to display an add comment button(like in here or FaceBook) for all of the users' posts.
As you can see in here, if you click "add comment" button, small input box opens and your comment appears right below where you add it with smaller size than normal posts.
I am confused about which language would be the best for this. I know a little about JavaScript and jquery but i think doing it with php is not possible. An idea or example to do that would be greatly helpful.
JavaScript shows the form field, than makes an Ajax call to the server when the person clicks the add content button.
The server saves the content to the database, and returns a success message.
If successful, the JavaScript shows the comment and hides the form fields.
JavaScript and jquery its a client side technologies. Php is a server side. You need a proper database design and can choose any sever technology you like.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am updating 100,000 records. So the page looks blank while the update query process runs on the backend. Can someone tell me how to display the text "Please wait blah blah" until the update ends?
Well depending on your script and the structure, the easiest way would be to change a div's css property called display. When a user clicks on a link that starts the php script, you could add a javascript code like :
$(#+THEIDOFYOURDIV).show("slow");
});
and once its done, you can call another js function to close it like :
$(#+THEIDOFYOURDIV).hide("slow");
});
*NOTE I am using jquery functions, so you would need to include jquery in your pages.
There is another way you could do this using php ONLY, I had the same issue so take a look at this: how to show results while a php script is still running