Jump to content

general question on mysql_fetch_array


turpentyne

Recommended Posts

I'm a newbie just trying to get an idea of whether my idea is possible and how, before I sit down to try writing this code (because it's on a page that's got a heck of alot of code on it already)

 

I want to access a specific table, then pull the info from one column from every row that matches a specific variable, and then use that array to insert information into a second table. I'm getting the sense that WHILE and  mysql_fetch_array is how I might do this. Or will it only give me the entire row? Can someone give me just a quick idea how I'd do this so I'm not flying too much in the blind?

 

thanks!

Link to comment
https://forums.phpfreaks.com/topic/208949-general-question-on-mysql_fetch_array/
Share on other sites

oh? haha! in other words, I might be overthinking this one. heheh! beginners!

 

Probably because I'm still rough at trying to figure out arrays. it would be several rows.

 

Like searching a table for any column that matches U.S.A.. It would return 50 states.

 

 

 

 

I quickly wrote this out. Is this close to what I would want to do?

 

$query = ("SELECT column2 FROM table1 
WHERE column1 = $variable")

$result = mysql_query($query);

if (!$result) {

while ($row = mysql_fetch_assoc($result)) {
INSERT INTO table2 (columnA)
VALUES ($row['column2'])
}  

Yes thats sort if it. However you should note that MySQL has a SELECT INTO statement, which will write the results of an SQL query into a table. An example can be found here

http://www.w3schools.com/sql/sql_select_into.asp

ah! Now that I've looked into it, that makes it alot simpler. But now that leads me to another question. I didn't mention that I have another variable (from a form) that has to be combined when inserting into the second table.

 

Each row would be: column 1 that comes from the form, and column 2 that comes from the first table.

 

Is there a way to do this using SELECT INTO? I saw some words used like UNION. Does that work to combine a form and a table query?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.