I am a php programmer.When a page gets loaded some records are shown from a table(in a tabular format on the php page) , on the page there are html submit buttons corresponding to whose post some other values are to be shown.
The problem is, the other values are shown along with the values which are shown when the page first loads. I want to show fresh set of values , without the default values which are shown when the page first loads.
It has to be mentioned that the default page load values which are fetched from the table is not done corresponding to any isset($_POST) unlike the other fresh values.
can you help me out?
Try using some random numbers in the query or other patterns in the query so that you get records afresh than getting the same records every time you visit the page.
Hope my understanding is right.
Related
I have a PHP page which displays n number of records in form of table from database(till here pagination works fine). Using a search field i am triggering another query, which displays the results in 2 pages. The first page shows the result fine, but when i click on the 2nd page link, it displays the result from the initial query.
any suggestions would help me to identify the actual issue that is causing this.
Thanks!
As a was stuck with same issue earlier.
The solution is to pass searching input value along pagination parameters.
In your case pagination just take it's parameter and performs its working by excluding searching query.
So just passing searching input value(Query) you will get proper result.
This is my first time posting in stackoverflow so please tell me if I need to add more information!
I am attempting to take a value from the mysql database and add 1 to it when the page loads. The user clicks on the link on the first page and when the linked page is loading and the php code below runs it adds 1 to the value of the column Clickcount in the entry with the Name value TheButton in the table "lots".
The following code worked when I ran it through Dreamweaver with WAMP:
<?php
$con=mysqli_connect("localhost","root","qwerty71","Lots");
mysqli_query($con,"UPDATE Lots SET Clickcount=Clickcount+1
WHERE Name='TheButton'");
$result=mysqli_query($con,"SELECT * FROM Lots where Name='TheButton'");
while($row= mysqli_fetch_array($result))
{
echo $row['Clickcount'];
}
mysqli_close($con);
?>
But when I put the same code into my website (only changing the values after the mysqli_connect to connect to the database) it doesn't work. The echo at the bottom is to show the value after it is changed, I have the same echo on the first page to show the value before it is edited by the second page. I set the value to zero in the database before I loaded the first page or clicked the link. The first page shows the value at zero, and after clicking the link the second page changes the value and displays a 1. When I try to click back to the first page it shows a 1 instead of a zero, but then both pages continue to display 1s instead of adding 1 every time the link is clicked.
I have tried multiple ways of changing the code after the SET Clickcount=
Including attempting to add a variable before query that I set equal to the Clickcount value and trying to add 1 to that.
Is there an error in my code that would prevent it from working properly, or is there an alternate way to set this up to get the desired result?
Re-explanation for clarity:
My table is as follows:
Name Clickcount
TheButton 0
I am trying to increase the value under "clickcount" by 1 every time a page is loaded. My code (posted above) functioned properly when run on a local server, I changed the parameters to match my server online.
The homepage has a portion of the code above to show the value of the Clickcount column and a link to the second page, where the code above is located.
The code functioned once, changing the value from zero to one, but then ceased to work on consecutive attempts.
Is there an error in my code? Or is there a better way to accomplish the task of increasing the value?
Further update:
The code seems to be working once every 5-10 minutes. I have left it as it is above, and it was not doing this before. I do not know what changed.
In addition, every few times that it does work, I get the result of receiving two different values when calling the following portion of the code on two separate pages:
$result=mysqli_query($con,"SELECT * FROM Lots where Name='TheButton'");
while($row= mysqli_fetch_array($result))
{
echo $row['Clickcount'];
}
mysqli_close($con);
This code is on the homepage, where it sometimes results in a number one less than what the value is recorded to be in the mysql table. Where on the page with the complete code listed above, it always shows the same value as in the table.
In my continuing effort to figure this out, I have removed all of the files off of the server where my site is hosted, and started again from scratch. After re-writing all of the code for the two pages, creating a new table in a new database, and implementing the code above on the second page, the error remains.
I have also just now signed up for a new hosting service to see if it was the server that was causing the problem. Sadly, that was not it. Does anyone have a suggestion for a solution?
Look to this points:
Copy your query and put in the database. It works?
In the end of your update line, put or die(mysqli_error($con)). If show errors, look to error;
There value 'TheButton' in the column Name in your remote table?
Try change in the clause where in update query, Name='TheButton' to Name LIKE 'TheButton'
Always throw messages errors in your codes. Is the best way to find mistakes. ;)
The page was loading a cached version instead of loading from the site itself. I added some coding to the header to remove the caching, this fixed the problem.
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 )
I have access for only to a front end of a webpage.
This webpage has fields like
Name
Age
Number
For the above i have to update Number field.
Similarly there are hundreds of similar webpages with the these fields which are needed to be updated.
For example URL of this webpage is https://stackoverflow.com/id=xx
In the URL the value xx of the 'id' is unique for each webpage.
I have these values xx of the 'id' and the corresponding age which needs to be updated in the webpages iteratively and be saved.
What are ways for doing the above?
have them displayed in a single page or paginate it instead of having to view them one per page, one item per line, put the values that would be changeable in a input type=text with a corresponding submit button beside each.
well you could get url parameters by using $_POST['id'], $_GET['id'] or $_REQUEST['id'] but try to validate the values first to avoid sql injections.
if you want to get the whole url itself you could use
$_SERVER['SERVER_NAME']
$_SERVER is default variable on php it has a lot of uses just try to visit this link http://php.net/manual/en/reserved.variables.server.php.
I hope it helps. :)
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