Jump to content

Archived

This topic is now archived and is closed to further replies.

desithugg

need help

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

Share this post


Link to post
Share on other sites
Try changing the query to:
$query = "update signup set slot='$count' where username='$user_currently_loged'";

If that doesnt work, post the full code, maybe there's an error somewhere else.

Orio.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
i dont want to make it zero i want to number them starting from 0 going up by 1 each time

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.