Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT and UPDATE?

Status
Not open for further replies.

MySqlRuben

Programmer
Jun 18, 2007
5
PT
Hi!

I'm a newbie in MySql, so please bear with me. What I want is to select all the informations concerning a specific article, and then to update a field of the resulting query. So, with some help I managed to do something like this

Code:
$query = sprintf("SELECT [I]CONCAT('UPDATE articles SET visits=(visits+1) WHERE title='".$name_article."'')[/I] 
                 FROM articles a 
                 LEFT JOIN autors b ON a.autor = b.name
                 WHERE a.title='".$name_article."'");  

$result = mysql_query($query);

Without the part in italic, it works pretty good. But I wanted to update that specific field without doing another query. Any help is definitely appreciated!


 
why SELECT?

just run the part in italics by itself --

UPDATE articles
SET visits=(visits+1)
WHERE title='".$name_article."'

r937.com | rudy.ca
 
Thanks for answering r937. But then how would I do the other part of the query?
 
i don't understand "the other part"

UPDATE and SELECT are separate operations

could you please repeat what you're trying to do?

r937.com | rudy.ca
 
What I want is to be able to select all columns from the article table and autors table, based on the article name, and, at the same time, update a field in the article table. I really dont know if its even possible to do that in one single query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top