The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Help with mysql php update
Hiya. Basically what I'm trying to do now is grab a
$upstck = $DB_site->query("SELECT stock FROM user"); What is being grabbed is a string and I need to split it, grab the first two chars, change the next two to 00, and then grab the rest, combine it and put it back :P So for '12345678', I'd need to grab '12' as the first, '34' and change it to '00' and then grab whatever is left over and throw it all back together and get '12005678' I'm totally lost or baffled by what I'm trying to do atm. This is for like 40,000 things, not just one btw. :P :ermm: |
#2
|
||||
|
||||
OK, so you'll have to run through all those 40'000 things with a while() clause:
while($stock = $DB_site->fetch_array($upstck)) { Then, parse the string: fetch the first two chars: $firstpart = substr($stock[stock],0,2); fetch the last part $lastpart = substr($stock[stock],4); and put it all together: $wholething = $firstpart . "00" . $lastpart; all together that makes this: PHP Code:
now I don't know what you want to do with the data, but do whatever you want where I placed the comment. |
#3
|
|||
|
|||
Then would something like this put them all back in their right spots?
$DB_site->query("UPDATE user SET stock = '$wholething'"); That'd get them all back where they are supposed to be? =/ or perhaps I'd need to take another field like userid to make sure they all match back up? |
#4
|
|||
|
|||
Ok, I'm pretty sure what I just said is bad. So how do I set it correctly? :P
|
#5
|
||||
|
||||
exactly, you need another field (like userid) to only update the one you changed (and not all of them).
$DB_site->query("UPDATE user SET stock = '$wholething' WHERE userid = $stock[userid]"); you'll also have to fetch the userid first, making it all together: PHP Code:
|
#6
|
|||
|
|||
Ah, worked. You're my php/mysql hero Colin! :P
|
#7
|
||||
|
||||
Glad to have helped
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|