PDA

View Full Version : more problems


Dimava
Thu 23rd May '02, 9:16pm
$result = mysql_fetch_array ( mysql_query ( "SELECT * FROM tutorial_amount WHERE id=1" ) ) ;
$one = $result[one];
$two = $result[two];
$three = $result[three];
$four = $result[four];
$five = $result[five];
$six = $result[six];
$seven = $result[seven];
$eight = $result[eight];
$nine = $result[nine];
$ten = $result[ten];
$eleven = $result[eleven];

if ($category == '1') $one += 1;
if ($category == '2') $two += 1;
if ($category == '3') $three += 1;
if ($category == '4') $four += 1;
if ($category == '5') $five += 1;
if ($category == '6') $six += 1;
if ($category == '7') $seven += 1;
if ($category == '8') $eight += 1;
if ($category == '9') $nine += 1;
if ($category == '10') $ten += 1;
if ($category == '11') $eleven += 1;

$query = "update tutorial_amount one='$one', two='$two', three='$three', four='$four', five='$five', six='$six', seven='$seven', eight='$eight', nine='$nine', ten='$ten', eleven='$eleven' where id =1 ";
mysql_query($query);


the code above doesn't work

thanks

Dimava

Mark Hensler
Fri 24th May '02, 12:23am
Your updating that record the hard way. Try this..

$query = "UPDATE tutorial_amount SET ";
switch($category) {
case 1: $query .= "one=one+1"; break;
case 2: $query .= "two=two+1"; break;
case 3: $query .= "three=three+1"; break;
case 4: $query .= "four=four+1"; break;
case 5: $query .= "five=five+1"; break;
case 6: $query .= "six=six+1"; break;
case 7: $query .= "even=even+1"; break;
case 8: $query .= "eight=eight+1"; break;
case 9: $query .= "nine=nine+1"; break;
case 10: $query .= "ten=ten+1"; break;
case 11: $query .= "eleven=eleven+1"; break;
}
$query .= " WHERE id=1";
mysql_query($query);

Dimava
Fri 24th May '02, 5:26pm
Thanks again Mark Hensler, you're like a php god

Dimava
Fri 24th May '02, 5:48pm
The reverse of this doesn't seem to be working:


$result = mysql_query("SELECT catgroup FROM tutorials WHERE id=$id");
$query = "UPDATE tutorial_amount SET ";
switch($catgroup) {
case 1: $query .= "one=one-1"; break;
case 2: $query .= "two=two-1"; break;
case 3: $query .= "three=three-1"; break;
case 4: $query .= "four=four-1"; break;
case 5: $query .= "five=five-1"; break;
case 6: $query .= "six=six-1"; break;
case 7: $query .= "even=even-1"; break;
case 8: $query .= "eight=eight-1"; break;
case 9: $query .= "nine=nine-1"; break;
case 10: $query .= "ten=ten-1"; break;
case 11: $query .= "eleven=eleven-1"; break;
}
$query .= " WHERE id=1";
mysql_query($query);


thanks

-Dimava

scoutt
Sat 25th May '02, 12:55am
you are select a dynamic id in the first select statement then you update the id where id=1

Dimava
Sat 25th May '02, 1:43am
actually its two seperate queries

Dan615
Sat 25th May '02, 1:46am
I don't know what context that snippit of code is running in, but you could also make category = one, category = two, yada yada yada...


mysql_query("update tutorial_amount set $category = $category + 1");

// or

mysql_query("update tutorial_amount set $category = $category - 1");


I don't know what you're doing with it, but that's what I would do to make life easier :)

Dimava
Sat 25th May '02, 1:49am
that wouldn't work with the way I have my table(s) setup

scoutt
Sat 25th May '02, 2:52am
Originally posted by Dimava
actually its two seperate queries
sure it is, then where is the cargroup coming from?

you select id, say 9, but then you update id 1.

unless catgroup is not from that select query. then why have the query there at all.

Mark Hensler
Sat 25th May '02, 5:01am
Originally posted by Dimava
The reverse of this doesn't seem to be workingSo the adding works, but not the subtracting? hmm... odd. try doing this...

one=(one - 1)

I don't think it should make a difference, but...

Dan615
Sat 25th May '02, 12:36pm
Where is the $category variable coming from? Is it part of the query string?

scoutt
Sat 25th May '02, 12:57pm
the first post you have

$result = mysql_fetch_array ( mysql_query ( "SELECT * FROM
tutorial_amount WHERE id=1" ) ) ;

$query .= " WHERE id=1";

and the reverse you have


$result = mysql_query("SELECT catgroup FROM
tutorials WHERE id=$id");


$query .= " WHERE id=1";

that is the only difference between the two. other than that it should work like the one Mark did.

Dimava
Sat 25th May '02, 2:58pm
the first query just pulls out the value of catgroup from a diffrent table, and then uses the catgroup value in another query

-Dimava

scoutt
Sat 25th May '02, 3:44pm
well then what errors are you getting? did you use the error statement Mark did for you the other day?

Dan615
Sat 25th May '02, 4:10pm
error_reporting(8) to see anything that might be going wrong...