Jump to content

Query a database using array elements

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
billmike

billmike

    Newbie

  • Members
  • Pip
  • 1 posts
Hi, I am an absolute newbie to PHP programming. I am only farmiliar with the scripts. I have a Mysql database from which I am able to query and put the results into an array. I would now like to use these array values, one at a time to query the database. I understand that results from a database are called resources and they have to be converted into variables before they can be used. Please help me to do this.

#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
$query = mysql_query("SELECT id,name FROM users LIMIT 10") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
	$arg[$row['id']] = $row['name'];
}

foreach($arg as $id => $value) {
	msyql_query("INSERT INTO backup SET `id`=$id, `name`='$value'") or die(mysql_error());
}