Jump to content

need help


desithugg

Recommended Posts

[code]
$count = "0";
$count++;
$query = "update signup set slot = $count where username = '$user_currently_loged'"; 
$result = mysql_query($query);
[/code]

will this number the slots going up by 1 each time and theres a reason im not using suto incretment
Link to comment
Share on other sites

[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
Share on other sites

If it's the whole code, where the connection to the database? And why do you use a var, instead of directly making it a zero:
[hr]
[code=php:0]
//connect to DB
$query = "update items set slot='0' where trainer = '$user_currently_loged'";
$result = mysql_query($query);
[/code]
[hr]

Orio.
Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.