Table 1 – users
id username items
1 Paul 1(0020);2(0001);
Table 2 – items
id name
1 name_here
In my user’s items I put 2(0001) which means: 2=item id, 0001 is the amount of it
Here is a function that displays my item list
function getitems() {
$username = $_SESSION['user'];
$connect = mysql_connect("localhost","root","x") or die("Conexiune nereusita!");
mysql_select_db("skameron") or die("Baza de date nu exista!");
$query = mysql_query("SELECT * FROM users WHERE username='" . $username . "'") or die(mysql_error());
if(mysql_num_rows($query) == 0) {
echo "<tr><td colspan=\"3\">Nu ai iteme in inventar!</td></tr>";
} else {
while($itm = mysql_fetch_assoc($query)) {
$str = $itm['items'];
$items = preg_split("/;/", $str);
foreach ($items as $item){
$temp_item = preg_split("/,/", $item);
if($temp_item){
foreach ($temp_item as $temp_i){
If($temp_i=="")
{
}
else{
$pieces = substr($temp_i, -5, 4);
$piecesold = $pieces;
$pieces = $pieces/1;
//$arrnr = array(0,1,2,3,4,5,6,7,8,9,"(",")");
//$temp_i = str_replace($arrnr,"",$temp_i);
$query2 = mysql_query("SELECT * FROM items WHERE id='" . $temp_i . "'") or die(mysql_error());
if(mysql_num_rows($query2) == 0) {
echo "<tr><td colspan=\"3\">Nu ai iteme in inventar!</td></tr>";
} else {
while($itm2 = mysql_fetch_assoc($query2)) {
$temp_i = $itm2['name'];
$temp_id = $itm2['id'];
echo $temp_i . " <a href='items.php?del=". $temp_id."(".$piecesold.")'>Delete all</a>(". $pieces . ")/<a href='items.php?del=". $temp_id."(".$piecesold.")&nr=1'>Delete 1</a><br>";
}}}}} else {
echo $item;
}}}}}
I made the page to delete an item but I can’t find a way to delete just the amount of items…for example to change this: 2(0100);1(0001); to this: 2(0099);1(0001);
Here is how I did to delete a value like this:
$delitem = $_GET['del'];
$queryreg = mysql_query("UPDATE users SET items = REPLACE(items, '$delitem;', '');");
I can delete with this page a value like 2(0099); and the others remain…
But I can’t only change the amount of item which is 0099/1=99
You really should consider changing the layout of your data
Now paul has 100 of SomeItem and 99 of AnotherItem