Populate second table on click - php

I've got a table listing all users with their basic information, the last cell of the row is a 'view more', which should populate a second table with detailed information about the user. (see it as 2 panels, left and right, and right one (view more) only displays when view more is clicked).
All the data is stored on the database, I've already succesfully managed to build the first table. But the problem is how to handle the second one, I've build it, and depending a variable it loads content from one user or another, but I don't know how dynamically change that value and load the next user data on the fly. Thanks in advance.

You can't load data on the fly in php. the simple reason is because the http protocol doesn't work like that.
You basically have 3 diffirent options:
1. reload the page with another link
2. Use ajax to load the data async
3. Load all the data on the start and hide missing data on page load, and show it when you click more info

Related

How to execute mysql_fetch_row() upon a button click

I am tying to put some user data from the database using php.
The database contains so many record and i am displaying it using mysql_fetch_row() and this gives me the fields of first row.
Now the problem is a have two buttons namely next and previous. And when a click next the fields in the next row has to be obtained the they should be inserted into page without loading the page once again. I am facing problem with this.
I am using php for server side programming and html, css for client side programming.
I think that no one will give you the answer. Too many to write. You need to read about ajax (this is the technology that will allow you to do some action without page reloading).
You need to write javascript(you can use some library like jquery) function which will open some php page with the data that you want and then update your site.
Here you have some nice tutorial:
http://www.w3schools.com/jquery/jquery_ajax_intro.asp

How to keep results filtered by selectbox even after page refresh

I'am using the CodeIgniter. I have a global category list, which is separated into the several components such as (Conten articles, E-commerce, Users, Banners, etc...). There is /categories/get_categories page where I display all rows from Database Table ci_categories.
On that page, there is a <select> box with the <options> of available ci_categories.com_id (components). Whenever I select one of them, either Users or E-commerce it will send the POST data /categories/get_categories/$com_id and it will filter the category items corresponding to the component's id com_id. All of this works great.
But what I want is to keep this filter selected and do not return to default selection (all components). For example, I click on Categories - it will output all category rows in a <table>. There I choose an option from a dropdown selectbox list, and it will filter the specific rows output, then i Click Add new category, and it should pass that selected component option to the next page. On the next FORM page, where I add a new item informations, i Click on SAVE, and it should return me to the previous page where All of categories are listed, but with that filter com_id selected.
Any suggestion ? Is there a way to do it without sessions or cookies ?
My suggestion is to make use of sessions as they are especially meant to store data between requests based on the current user experience. Most people only search the website in one browser window, so it shouldn't give a real problem. Even if there are other options, you always need to identify the user by a specific code which will be stored in session/cookie.
The only option I can think of is changing every link afterwards to contain the stored information in a base64 encoded string. But that would ruin your link structure and needs canonical links on every page to show the right url to search engines.
I would suggest you to stick to Sessions, as they are handled fine in CodeIgniter. You can even store them in the database if you want by setting that in the main config file.
Flashdata is an option, but it's a session in the end anyway but only lives one request.
you can use session flashdata like this:
Set flashdata
$this->session->set_flashdata('search','your_search');
Read flashdata
$this->session->flashdata('search');
flashdata is setted for only one refresh, after the refresh the variable is deleted
http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

Update select contents without reloading form

I have quite a long form which has many HTML form selects pulling data from MySQL tables - quite often a client will be mid way through filling in the form when they realise that the value they want for department, for example, has not yet been entered into the system so is not in the list.
I have added a link to a simplified popup for adding departments but after it is added it does not appear in the select list as the contents of that select are based on what was available on the load of the page when the initial query ran - how can I get the select to update without having to submit and then edit, without the page refreshing/reloading and without the client losing the data they have currently added?
Thanks
Did read what you are asking, since its too long) But did you try javascript? changing form values after paged loaded is possible only with javascript.
When submit form on that popup, save it with ajax in database, and as response get inserted data... Then on ajax success add new option in select ( with returned data )

Store different data to each tab

I need store different post data to each tab in a browser. If I open a new instance of the same page, the data aren't shared between both.
My problem:
I'm building a CMS to control my website content. But I will open some instances of the same page (many tabs). So I have a search form to find news that I been created on my CMS. If I open a news item I have a cancel button that back to previous page (the news list).
The problem is that the news list have a pagination and a filter form. So I can, for instance, search by a term like "john doe" and advance to page 5, and open a news item. If I cancel, currently I back to news list without filter and on first page.
My solutions:
Well, I don't want to use the history.back() because I can submit a news form and click on back/cancel button. So, I'll back to the current form, what is wrong.
My second idea is to store a $_SESSION with the $_POST sent to the news list and the back button send me to /news/list/recovery-session, that will recovery the $_POST data from session. But it have a problem: if I open two tabs and make two searchs, I'll have only the last session saved.
Your solutions:
Well, I can work with PHP and JS to make it work. You can suggest a idea of what I can do. I think about work with COOKIES, but I belive that it is shared by domain, and not by tab, what is a problem.
Someone?
Generate a unique id and attach it to the form or some hidden element that will be submitted. Save that unique id in a cookie or session variable. Compare the two at time of submission.
If second tab has generated a new id, the first tab will not evaluate to true.
The main problem is the need to persist the state of what page to return to and also the search term when returning back to the news list page. There are many ways to accomplish this, but one simple method is by encoding this data into your query string.
As an example, assuming your search term is "john doe" and you are on page 5, pass that data along to your news page.
news.php?returnSearchTerm=john+doe&returnPage=5& ....
When the news page is created, you can format your cancel link to send you back to the list page with the correct parameters.
news_list.php?search=john+doe&page=5

fetching data from database in randomly generated button

i found it difficult,,,, fetching data from database while a buttons are randomly generated in for each how can i fetch
Without understanding what your question really is, you could go trough the mysql query result like this:
// button_text is a database column in this example
while ($row = mysql_fetch_row($result)){
echo "<button type="button">".$row['button_text']."</button>";
}
But to really help you, you need to rephrase your question!
I'll make some assumptions for what you are trying to do:
1. You have buttons that fetch more info from a db
2. The buttons are "randomly" generated, and each calls different info (pets, cars, etc).
You may or may not be using ajax, but I will describe it basically assuming straight php, and you are using a single page (for clarity in my explanation).
What you need to do is have each button either be a link or a submit for a form. This just depends on whether you want to use GET or POST. The buttons will have php generated links (if GET) or values (if POST). For example, using get the link could be "www.file.php?cat=cars". The button would just have the value of "Cars", and since bother are generated, that shouldn't be an issue keeping them the same.
When the page is now reloaded based on the click, the top of the page has a query in it to get the new info. For example, it would run a query looking for all items that have the car category. Then the new information would be displayed, and the new random buttons would show.
VERY IMPORTANT: Sanitize all GET and POST values before using them in a query

Categories