Question 1.
I have a table with multiple records in it. Each record has it's own timestamp. How do I select the most recent update based on the most recent timestamp?
Question 2.
Some of my users keep putting " ' " in there record updates. I have a form written in php that allows them to view and update certain info. For instance...they update a projects name with the following:
"George's project".
Since that is the projects name, I use that info on another form (passed through a link) to query for information. Problem is when I query the following:
"select description from projects where project.name='George's project';"
it tells me that my query produced no results. If I try to stripslashes(project.name) <---- php function or addslashes(project.name) it still doesn't work. But, if I use:
"select * from projects"
I can see that the projects name actually is "George\''s project". Why then can't I select the description (or any other info) for that project by matching the project's name?
display results from a query by most recent date
Moderator: General Moderators
1) SELECT .... ORDER BY fldName DESC
2) then you've done a bit too much
e.g.it will echo it''s a test but mysql stores it's a test. just likealthough there is a \" the actual value is only " and \ only escapes the special meaning of " in a double quoted string.
2) then you've done a bit too much
Code: Select all
$value = "it's a test";
$value = mysql_escape_string($value);
echo $value;
$query = "INSERT INTO texts VALUES('".$value."')";
mysql_query($query, $conn);Code: Select all
$value = "you have to escape "s in here";
echo $value;http://www.mysql.com/doc/en/Sorting_rows.html explains it .
If you want only the most recent entry you might limit the result set
e.g.http://www.mysql.com/doc/en/SELECT.html
If you want only the most recent entry you might limit the result set
e.g.
Code: Select all
SELECT * from table WHERE cat=5 ORDER BY tmInserted DESC LIMIT 1