Jump to content

need help


desithugg

Recommended Posts

[code]
<?
$count++;
$query = "update items set slot = '$count' where trainer = '$user_currently_loged'"; 
$result = mysql_query($query);
?>
[/code]

is the whole code and yess it is connected to the db it sets all slot rows as 1
what i want to do is update all the items owned by a certain user and number the row "slot" in order starting from 1 and i cant auto incretement because i only want to do it for 1 user at a time and start over from 1 for every user sorry if im confusing but really stuck at this and Count++ wont work so im looking for more ideas.
Link to comment
https://forums.phpfreaks.com/topic/17140-need-help/#findComment-72568
Share on other sites

That's something totally diffrent from what you wrote...

I made a script for you, but I am not sure if you can use LIMIT inside update and if it'll work like expected... Try and see:
[code]<?php
//connect to db here
$query_a="SELECT * FROM `table` WHERE trainer = '$user_currently_loged'";
$result_a=mysql_query($query_a);
$num_rows=mysql_num_rows($result);
$count=1;
while($count<=$num_rows){
$update="UPDATE `table` SET slot='".$count-1."' WHERE trainer = '$user_currently_loged' LIMIT ".$count.",1";
$result=mysql_query($update);
$count++;
}
?>[/code]

I think it'll work :)

Orio.
Link to comment
https://forums.phpfreaks.com/topic/17140-need-help/#findComment-72587
Share on other sites

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.