Jump to content

Terminaxx

Members
  • Content Count

    39
  • Joined

  • Last visited

Everything posted by Terminaxx

  1. Wow. Thanks you two! Especially for not just giving me the answer but also for the good explanation!
  2. Edit: Sorry to make it sound stupid again, but how exactly can I echo the sum correctly now? I tried this: while($row = mysqli_fetch_object($res)) { $name = $row->receiver; $row = mysqli_fetch_assoc($res); $sum = $row['value_sum']; echo "<tr>"; echo "<td>".$name."</td>"; echo "<td>".number_format($sum, 0, ",", ".")." Money</td>"; } Sorry if it is really easy for you and it annoys you, but I still try to learn and understand. It shows some results, but they are way too low so they can't be correct.
  3. Hey, thanks for your help it sound really logical. I also would like to thank you for your third hint. Going to consider it when I code again! Thanks again. Edit: Got it!
  4. Sorry but I don't really get it. I tried this: $result = mysqli_query($con, "SELECT SUM(action) AS value_sum FROM transactions WHERE comment = 'tax' ORDER BY receiver"); Did you mean this? Or how exactly am I gonna do this? Sorry but im kinda new to this.
  5. Hey guys, I got a table where transactions are listed in, therefore we got once the "receiver", the "comment" and the "action" (amount) For exmaple User A - something - 50 User B - something - 50 User C - tax - 100 User D - tax - 100 User D - tax - 200 User F- tax - 200 I want to get the sum from every action with the comment "tax" listed by users So it should be like this: User C - tax - 100 User D - tax - 300 <-- 200 + 100 User F - tax - 200 How can I do this? Thanks for any help and I hope it is clear, what I am trying to do.
  6. Got it now. Thanks for the explanations and sorry for annoying you.
  7. It still isn't working. Not sure what I am doing wrong. Could you add the code up, as i should have put it in to check if I got it correctly? Would be awesome! I got the above part from my latest version, where I didnt want to have them seperated. I am kinda confused about all the code here...
  8. Thanks, I understood it now. But I gotta annoy you one last time: <?php $res = mysqli_query($con, "SELECT s.name , s.price , s.quantity , s.img , s.id , s.owner FROM shop s JOIN ( SELECT name , MIN(price) as price FROM shop GROUP BY name ) mins USING (name, price)"); $furnis = array(); $names = array(); while($row = mysqli_fetch_object($res)) { $id = $row->id; $img = $row->img; $owner = $row->number; $name = $row->name; $price = $row->price; $quantity = $row->quantity; if(!in_array($name, $names)) { $f = new furnipack(); $f->img = $img; $f->quantity = $quantity; $f->name = $name; $f->price = $price; $f->id = $id; array_push($furnis, $f); array_push($names, $name); } } } foreach ($furnis as $f) { echo "<h3>$f->name</h3>"; echo "<h5>".number_format($f->price, 0, ",", ".")."</h5>"; echo "$f->quantity x"; echo "<input name='quantity[$f->id]' type='number' value='1' min='1' max='$f->quantity'>"; echo "<button type='submit' name='buy' value='$f->id'>Buy</button>"; } } ?> I got the total code now something similar like this. I mean, I still gotta put the results in variables right? How else would i echo them What did I do wrong - is it because of the "if(!in_array($name, $names))" code? or did i mistake something once again with your code?
  9. Thanks for the answers but I kinda dont understand the code (im quite new to this and just try to learn) Like I do not understand what you mean by s.price etc. - what is the s for? Why select something from shop s? I understood it like this: $res = mysqli_query($con, "SELECT * FROM shop"); while($row1 = mysqli_fetch_object($res)) { $name1 = $row1->name; $price1 = $row1->price; $res2 = mysqli_query($con, "SELECT * FROM shop JOIN ( SELECT name, MIN(price) as price FROM shop GROUP BY name ) mins USING ($name1, $price1)"); while($row = mysqli_fetch_object($res2)) { $id = $row->id; $img = $row->img; $owner = $row->number; $name = $row->name; $price = $row->price; $quantity = $row->quantity; } But I am pretty sure I did it wrong. Excuse me for my stupid question - it might sound clear to someone who isnt new to this. Thanks in advance
  10. Hey guys, I got a table something like this: ID name price quantity 1 name1 40 5 2 name1 50 6 3 name2 30 7 4 name2 40 9 5 name1 60 11 I want to only get the objects with the lowest price from everywhere where the name is the same. So for example, if we look at the table above i want to get name1 (price 40 - quantity 5) and name2 (price 30 - quantity 7) How can I manage to do this? I tried this, but this could be somewhere belong wrong: $res = mysqli_query($con, "SELECT * FROM shop WHERE MIN(price / name)"); Thanks for any help
  11. Hey guys, first i want to apologize for my english and hope you still understand the meaning of it. I list items that you can buy and also choose the number, how many items you want to buy. Code: foreach ($furnis as $f) { echo "<h3>$f->name</h3>"; echo "<h5>".number_format($f->price, 0, ",", ".")." Taler</h5>"; echo "$f->quantity x"; if($money >= $f->price) { echo "<input name='quantity' type='number' min='1' max='$f->quantity'>"; echo "<button type='submit' name='buy' value='$f->id'>Buy</button>"; }else { echo "<button>Not enough money</button>"; } } To get the aricle, which is clicked is easily done with getting the ID: $id = input($_POST['buy']); Now my question is, how to get the quantity (inputfield) right? When I try the same: $quantity = input($_POST['quantity']); I do not get the quantity. Of course I get it, if only one article is displayed, but there are many more. So instead of getting the quantity of the article the person clicked on, i get a random quantity from an other article. How can I do it right? Thanks for any help
  12. The main problem is, how to get the timestamp out of the table, add 1 day and put it as a new column in. Therefore I got problems with representing the timestamp in the right order. I tried this: $highdate = mysqli_fetch_object(mysqli_query($con, "SELECT * FROM auctions ORDER BY yourdate DESC LIMIT 1"))->yourdate; $date = date_create('$highdate'); date_add($date, date_interval_create_from_date_string('2 days')); (tried it here with 2 days) but in the table i got it in this format: 0000-00-00 00:00:00
  13. Hey guys, first I want to apologize for my English and hope you still understand what i am trying to do. So i got a table with many timestamps in it - like this: 2017-11-04 00:00:00 I want to get the object with the highest timestamp (the farest day) and add exactly one day to it and add it to the table. Like if we say the above timestamp was the highest, the next one should be like this: 2017-11-05 00:00:00 How can i do this and add it to the table without any error? Thanks for any help
  14. Thank you once again for a good answer with an example given.
  15. But the only thing i can do with it is see the DATEdifference between it. But i would also like to see the hour, minute and second diffrences. Is this somehow possible?
  16. Could you show me an example on how to do it and also show the results in days, hours, minutes and seconds? I would be very grateful
  17. Hey Guys. I got a timestamp saved in my database. Now i want to show the Timediffernce between now and the timestamp saved. I tried this: $date1 = time(); $date2 = $enddate; $diffDate = $date2 - $date1; $days = floor($diffDate / 24 / 60 / 60 ); $diffDate = $diffDate - ($days*24*60*60); $hours = floor($diffDate / 60 / 60); $diffDate = ($diffDate - ($hours*60*60)); $minutes = floor($diffDate/60); $diffDate = $diffDate - ($minutes*60); $seconds = floor($diffDate); echo "Time: ".$days."d ".$hours."h ".$minutes."m ".$seconds."s"; But it doesnt work. It shows something like this -19383d 16h 33m 37s Thanks for any help
  18. Thanks for the explanation!
  19. Hey guys, I am trying to add my databasetable the current timestamp (d-m-Y H:i:s) but adding to it 3 days. I tried this: mysqli_query($con, "INSERT INTO test (enddate) VALUES ('NOW() + INTERVAL 3 DAY')"); But the time is shown up as "0000-00-00 00:00:00" . I tried to fix it with strtotime but then it says that "NOW()" is invalid. Can someone help me with this issue? Sorry for my english, hope you still understand what i am trying to do. Thanks in advance.
  20. The code above isn't important, because it doesn't affect it at all. The input just makes clear, which ID it has to change. This works just fine. My only problem is this line: echo "<input name='newprice' value='$f->price' type='number' >"; Since this is the only NEW code which i add to the previous one. I dont understand how to make it work, that when I write the "newprice" inthere, I don't have to write a price for every other article on the page.
  21. <html lang="de"> <head> <title>Shop</title> <script> function keyispressed(e){ var charCode; if (e.keyCode > 0) { charCode = e.which || e.keyCode; } else if (typeof (e.charCode) != "undefined") { charCode = e.which || e.keyCode; } if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } </script> </head> <body> <form method="post"> <?php echo $error;?> <?php echo $correct;?> <?php if(isset($_POST["searcharticlename"])){ $search = input($_POST["searcharticlename"]); $res = mysqli_query($con, "SELECT * FROM shop WHERE name LIKE '%$search%' AND number = '$number'"); }else{ $res = mysqli_query($con, "SELECT * FROM shop WHERE number = '$number'"); } $count = countfurni($res); $sites = ceil($count / 40); if (empty($_GET['site'])) { $site = 1; } else { $site = $_GET['site']; if ($site > $sites) $site = 1; } $limit = ($site * 40) - 40; ?> <?php if(isset($_POST["searcharticlename"])){ $search = input($_POST["searcharticlename"]); $res = mysqli_query($con, "SELECT * FROM shop WHERE name LIKE '%$search%' AND number = '$number'"); }else{ $res = mysqli_query($con, "SELECT * FROM shop WHERE number = '$number'"); } $furnis = array(); $names = array(); while($row = mysqli_fetch_object($res)) { $id = $row->id; $img = $row->img; $owner = $row->number; $name = $row->name; $price = $row->price; $quantity = $row->quantity; if(!in_array($name, $names)) { $f = new furnipack(); $f->img = $img; $f->quantity = $quantity; $f->name = $name; $f->price = $price; $f->id = $id; array_push($furnis, $f); array_push($names, $name); }else{ foreach ($furnis as $f) { if($f->name == $name){ $f->quantity += $quantity; if($price < $f->price){ $f->price = $price; $f->id = $id; } } } } } $c = 0; foreach ($furnis as $f) { if ($c >= $limit and $c <= ($limit + 40)){ echo ".$f->name."; echo "<b>Price:</b> ".number_format($f->price, 0, ",", ".")." Taler<br>"; echo "<b>Quantity:</b> ".$f->quantity."</span><br>"; echo "<input name='newprice' value='$f->price' type='number' >"; echo "<button type='submit' name='changeprice' value='$f->id'</button>"; } $c++; } ?> </form> </body> </html>
  22. Hey guys, i got something similiar like a shop, not for others, just for me to try things out. Therefore I was trying to be able to change the price on my own: <?php $c = 0; foreach ($furnis as $f) { if ($c >= $limit and $c <= ($limit + 40)){ echo ".$f->name."; echo "<b>Price:</b> ".number_format($f->price, 0, ",", ".")." Taler<br>"; echo "<b>Quantity:</b> ".$f->quantity."<br>"; echo "<input name='newprice' value='$f->price' type='number' onkeydown='return keyispressed(event);' min='1'>"; echo "<button type='submit' name='changeprice' value='$f->id'>Chance price</button>"; } $c++; } ?> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { if(isset($_POST["changeprice"])){ $id = input($_POST['changeprice']); $row = mysqli_fetch_object(mysqli_query($con, "SELECT * FROM shop WHERE id = $id")); if (!empty($row)){ $furniname = $row->name; $price = $row->price; $owner = $row->number; $quantity = $row->quantity; $newprice = $_POST['newprice']; if($newprice >= 1 AND $newprice <= 80000000) { mysqli_query($con, "UPDATE shop SET price = '$newprice' WHERE id = '$id'"); $correct = "Price changed"; }elseif($newprice == 0){ $error = "No new value detected"; }elseif($newprice > 99999999) { $error = "New price is too high"; }else{ $error = "Furni doesn't exist"; } } } } ?> So this worked fine as long as I only got 1 item to change. If on the site there were more than one shown, it didn't work anymore. I think it is because of the "$newprice = $_POST['newprice'];" That it detects all prices from every furni, eventho I only clicked on one to change. So I tried it with "value='$f->price'", therefore I thought If I haven't entered anything in a column, the old price is taken over. But it doesn't seem so. I have to change the price from every furni shown, then click on the "Change Price - button" to change the ONE price, i clicked on. Is there any solution? Sorry for my poorly english, i hope you still understand what i mean. Here's how it looks like: http://prntscr.com/fqcii8 If I now enter a number in either of them, the price would not change. If I would enter a number in both and click Change price, the price changes from the selected one. Thanks for any help
  23. As i said i cut a little bit off. Seems like a bit too much. But thats not the problem. Just assume everything is fine. I am pretty sure its because of the explode. I think this doesnt work to explode: $id1 = $row->id."#1"; $idx = $row->id."#x"; $id2 = $row->id."#2"; What do you think about it?
  24. So.. once again i am trying to finish my script. But something doesnt seem to work. if ($_SERVER["REQUEST_METHOD"] == "POST") { $amount = input($_POST["amount"]); if(!empty($_POST["bet"]) and !empty($amount)){ $in = input($_POST["bet"]); $teile = explode("#", $in); $game = $teile[0]; $bet = $teile[1]; $res = mysqli_fetch_object(mysqli_query($con, "SELECT * FROM games WHERE id = $game")); if (!empty($res)) { ... ... ... $correct= "Success"; }else{ $error = "Not enough money"; } }else{ $error = "Game does not exist"; } } }else{ $error = "Please enter the amount you want to bet"; } } $res = mysqli_query($con, "SELECT * FROM games WHERE date >= NOW() ORDER BY date ASC"); while($row = mysqli_fetch_object($res)) { $id1 = $row->id."#1"; $idx = $row->id."#x"; $id2 = $row->id."#2"; echo "<tr class='tablerow'>"; echo "<td value='$id1' name='bet' >".$row->quote1."</button></td>"; echo "<td value='$idx' name='bet' >".$row->quotex."</button></td>"; echo "<td value='$id2' name='bet' >".$row->quote2."</button></td>"; echo "</tr>"; } It always causes the error "Game does not exist" I think i did something wrong with "explode" but Im not sure what exactly. I have omitted some unimportent elements here, if you need more information about something, just ask for it. And before someone asks, it has nothing to do with real money and its just a project to learn more things about php and co. Thanks for any help.
×
×
  • Create New...

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.