Jump to content


Photo

need help


  • Please log in to reply
8 replies to this topic

#1 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 10 August 2006 - 03:09 PM

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

will this number the slots going up by 1 each time and theres a reason im not using suto incretment

#2 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 10 August 2006 - 03:09 PM

looks good to me

#3 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 10 August 2006 - 04:19 PM

any 1 else have any ideas?

#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 10 August 2006 - 04:24 PM

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.
Think you're smarty?

(Gone until 20 to November)

#5 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 10 August 2006 - 04:27 PM

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

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.

#6 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 10 August 2006 - 04:48 PM

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:
 
//connect to DB
$query = "update items set slot='0' where trainer = '$user_currently_loged'";
$result = mysql_query($query);
 

Orio.
Think you're smarty?

(Gone until 20 to November)

#7 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 10 August 2006 - 04:49 PM

i dont want to make it zero i want to number them starting from 0 going up by 1 each time

#8 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 10 August 2006 - 05:02 PM

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:
<?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++;
}
?>

I think it'll work :)

Orio.
Think you're smarty?

(Gone until 20 to November)

#9 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 10 August 2006 - 05:02 PM

What are you trying to do desithugg?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users