The main code which i use is
while ($row = mysql_fetch_assoc($result1)) {
echo $row["user_id"];
$new = "[grade uid="{$row["user_id"]}" value="{$groupgrade}" format="{$groupformat}" prv_comment="{$groupprivatecomment}" pub_comment="{$grouppubliccomment}"] ";
$sqq = "UPDATE wp_postmeta SET meta_value='$new' WHERE meta_key='grade' AND post_id= $post_id ";
$result = mysql_query($sqq);
echo "grade has been updated";
}
Which affects the rows in table wp_postmeta as shown in the picture on the link Where all the variables undefined here are defined before this para .
What i actually want that user id must be different in different rows.
The only thing happening in this loop is that each uid from the array gets written in all the rows one after the other and only the last uid persists finally which is 3 in the diagram but i only want that each uid should come separately i.e., differnt uid for diff. meta_id . Please help
REGARDING CODE
$result1 fetches an array of userids from a defined mysql function and rest variables are user defined.
I am kinda new to php and to programming so please help
The
question
is not very clear and it’sWordPress
related and you didn’t addWordPress
tag in your question. Anyways,WordPress
has it’s own function to handle post meta. In your loop you are trying to update post meta manually but it’s possible to do that using WordPress’ update_post_meta function. The syntax is given bellowIn this case you can use following code
Here
$post_id
will be your post id which you want to update.OK, now that I understand your problem (you confused me by saying that “all rows” were being updated, you just mean all rows with this
post_id
), I think this is the answer:The new
$sql2
query gets eachmeta_id
, and updates each row with a differentuser_id
from$result11
.your code is to work around this
$row["user_id"]
if this variable is from other query then u must look to this query how u getting this
user_id
or , publish it in your question , to see why it comes only 3.its better to make a column for
user_id
to insert data specialy for that user.$row["user_id"]
is beeing a warning variable to sql injection , so it must be escaped bymysql_real_escape_string()