Read more coverage from CNN affiliate KGTV
(CNN) -- A gunman faces six counts of attempted murder after he opened fire at an elementary school in California and injured two students who were outside during lunch, authorities said.
The students, ages 6 and 7, suffered minor injuries in the Carlsbad shooting, said Lt. Jay Eppel of the Carlsbad Police Department.
Both were flown to Rady Children's Hospital in San Diego. Police indicated the students were grazed by bullets.
The alleged gunman was identified as Brendan O'Rourke, police said.
Construction workers at Kelly Elementary School detained a 41-year-old male suspect shortly after noon until officers arrived, Eppel said. Police do not suspect the man has a relationship with any students at the school.
Worker Carlos Partida said he got into his truck and was able to knock the gunman down with the vehicle. The man, dressed in black, was then tackled by other construction workers and witnesses.
The gunman made some reference to President Barack Obama, Partida said.
The suspect's vehicle was parked near the school. Officers found a handgun and propane tank inside, police said. The bomb squad was called to the scene to conduct a more thorough search, Eppel said.
The suspect was taken to a hospital after he complained of back and neck pain, and faces six counts of attempted murder and numerous weapons violations, police said.
Police said the suspect provided three names, one of them a woman's name, when asked for identification.
Third-grade student Shaylyn Foley was on the playground with her friend and told CNN affiliate KGTV what she saw.
"I saw him and he was across the street. Phoebe said, 'Who is he?' Then I'm like, 'Phoebe, he might not be a good man.' Then he put his hand out and then I heard the shot, and then I'm like, 'Phoebe, come on, this isn't OK.'"
Shaylyn and her friend ran away as the gunman fired.
Students were taken to a local park to be picked up by their parents.
Pete Anderson, who operates a small research vineyard near the school, said he was tending vines when "I heard something like a gunshot, followed by another."
Three more shots followed about 30 seconds later, he said.
Children were yelling as they ran from a playground back toward the school, Anderson said.
"At this point, I knew this was not a drill," he told CNN.
Anderson said he did not see the accused shooter until after he was taken into custody.
CNN's Phil Gast contributed to this report.