mysql - Update database table with PHP -


i trying update products category in database. want find products have in name specific word , after want update category products.

i want select ids sho_posts sho_posts.post_title contain part of word '%audio cd%' , after update sho_term_relationships.term_taxonomy_id value 2 sho_term_relationships.object_id=sho_posts.id.

i wrote little php code make selection part. wrong?

 <?php   $username = "user_name"; $password = "password"; $hostname = "host";  //connection database $dbhandle = mysql_connect($hostname, $username, $password)     or die("unable connect mysql");  $selected = mysql_select_db("1812233_shoping",$dbhandle)     or die("could not select examples"); echo "connected mysql<br>"; $result = mysql_query ("select `id` `sho_posts` convert(`post_title` using utf8) '%audio cd%' "); while ($row = mysql_fetch_array($result)) {     echo "id:".$row{'id'}."<br>"; }  $sql =  "update 'sho_term_relationships'    set 'term_taxonomy_id' = '123'  'object_id' = $row"; //close connection mysql_close($dbhandle); 

my new cod script is:

$username = "_shoping"; $password = "password"; $hostname = "localhost";  //connection database $dbhandle = mysql_connect($hostname, $username, $password)     or die("unable connect mysql");  $selected = mysql_select_db("_shoping",$dbhandle)     or die("could not select examples"); echo "connected mysql<br>"; $result = mysql_query ("select `id` `sho_posts` convert(`post_title` using utf8) '%audio cd%' "); while ($row = mysql_fetch_array($result)) {     $id[] = $row['id'];     /*echo "id2:".$id."<br>";*/ }   foreach ($id $value) {     echo "value:".$value."<br>"; }  /*$id = $row['id'];*/ $sql =  "update sho_term_relationships          set term_taxonomy_id = '123'          object_id =".$value; mysql_query($sql); //close connection mysql_close($dbhandle); 

now make update 1 row, how make rows? select query 4 result

try this:

$sql =  "update sho_term_relationships          set term_taxonomy_id = '123'          object_id = ".$row{'id'}; 

and make sure run query mysql_query($sql)

also, think might want add query inside while loop


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -