Jump to content

javanoob

Members
  • Posts

    31
  • Joined

  • Last visited

javanoob's Achievements

Member

Member (2/5)

0

Reputation

  1. Ok. I'll make note of that and make the changes. Thank you!
  2. Thanks. I'll replace all instances of ( $row['gm'] ) with ( $row['gm'] ?? 'X' ). Em$ and Gm$ are the game's currency. Em$ is the premium currency, it can be bought with real money. Gm$ is awarded for completing missions and harvesting hunted animals. I assume it might stand for Evergreen Money and Game Money but I don't know for sure. The knowledge base for the game doesn't define them if they are acronyms. Evergreen Hunting Reserve is the name of the game's world.
  3. Thanks! I'll give that a try. Learning from that SQL link is on my to do list. Some items can only be bought with EM. For those items I have an X appearing in the gm field. The X messes up the totals calculation. How can that be prevented? let X = 0;?
  4. Doesn't that require indexes so it knows where to look? Or is that what the rfl.id = rs.rifle_id in the sql is doing? There's only a few different prices for ammo. That's what I intended the a_em and a_gm columns in the database and the number input like this is for under Ammo Qty on the front-end table. I already have the columns filled in. It's not difficult to delete the whole column (it's excel/calc) if it's better to do as you suggest.
  5. Thanks! I was confident you'd know of a way to do that. I think I found a script that'll populate the 'scope' menus based on what rifle's selected. I want to get the database completed with all the items in it before I give it a try.
  6. ยท Scopes for the weapons. Each weapon doesn't mount the same scope. Some weapons have 4 available scopes they can mount, some have 2, some have 8 and they're not all the same scope sets for every weapon. There are 42 different optics in the game including binoculars, spotting scopes, and range finding binoculars. Vice versa for the scopes them selves. Same thing though. This weapon can mount 5 different scopes. This one can only mount 2 different scopes that are available. Click on one of the scopes on either of those pages then click on this scope to see the weapons it can be mounted to. It's not all perfectly the same. It would be a nice to have a feature that a weapon populated a selection menu of the scopes that fit. I was considering giving every item that has an accessory an accessory id (acs_id) and making a different table for that: I'm working on putting that data together. I'm thinking if I make a table of sets with scope_set_id's and a table of individual scopes with a scope_id's to handle that it should work out. Suggestions welcome and appreciated.
  7. That's what I was missing. It works now. Thank you! Is it possible to design the layout like this with how the code is now?: I'd like to fill the page if that's possible with how the code is now. I'll try making separate php files and use <? include 'file_name.php' ?> to do that. If I can't be done with the code as it is that's fine. It works. I'm so very extremely grateful for the help! Thank you so very much, Barand!!! It does need to calculate totals and balance from user input. That and a [ - ] button to remove rows that are added are my next attempt at trying to write javaScript.
  8. How do I define pdoConnect()? I didn't do that. This is my connect.php file (local WAMP): <?php $servername = "localhost"; $dbport = '3306'; $dbuser = 'root'; $ddbname = 'barands_code'; $bpass = ''; try { $pdo = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8;'", $dbuser, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false,PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?> That's all of it. There's nothing else in it. I added these 10 lines to the file. That's what pushed 67 to 77. $servername = "localhost"; $dbport = '3306'; $dbuser = 'root'; $ddbname = 'barands_code'; $bpass = ''; catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } The line 77 error went away when I started using the connect.php file. The only line being reported as erroring now is line 3 which is the $pdoConnect('db_name'); line. As sure as I can be. Every time I tried doing this differently I made a new folder. I compared the code I have to the code you posted here in this thread side by side line for line. I'll run them in WinMerge if my connect.php isn't missing something it needs.
  9. The only thing I can think of is I have the $pdoConnect('code'); wrong. <?php require 'connect.php'; $pdo = pdoConnect('barands_code'); I didn't change anything else. 'barands_code' is the name of the database. The error is on line 3 now. So...I have that wrong. What am I supposed to have $pdoConnect('HERE');?
  10. Here's line 1 to the end of </script> : <?php require 'connect.php'; // contains db credentials and connection function code $pdo = pdoConnect('barands_code'); // YOU WILL NEED YOUR OWN PDO CONNECT CODE // YOU WILL NEED YOUR OWN PDO CONNECT CODE ################################################################################ ## ## ## Handle AJAX request when + button is clicked ## ## ## ################################################################################ if (isset($_GET['ajax'])) { if ($_GET['ajax'] == 'newrow') { exit( tableItemRow($pdo, $_GET['catid']) ); } } ################################################################################ ## ## ## Query db item table to get all the categrories for the output table ## ## ## ################################################################################ $res = $pdo->query("SELECT id , itemname , em , gm , cat_id , cat_name FROM item i JOIN category c USING (cat_id) WHERE cat_id IN (1,2,3,4) ORDER BY cat_id, itemname "); $data = []; foreach ($res as $r) { if (!isset($data[$r['cat_id']])) { $data[$r['cat_id']] = [ 'catname' => $r['cat_name'], 'items' => [] ]; } $data[$r['cat_id']]['items'][] = array_slice($r, 0, 4); } ################################################################################ ## ## ## Loop through the data array to build the output table ## ## ## ################################################################################ $tdata = ''; foreach ($data as $cid => $cdata) { $tdata .= "<tbody data-cat='$cid'> <tr> <td class='cat-title' colspan='4'> {$cdata['catname']} <div class='addmore' data-cat='$cid'><i class='fa fa-plus'></i></div> </td> </tr> <tr> <td><select class='item-menu' name='item[]' onchange='item_menu_changed(this)'> <option value='' data-em='0' data-gm='0'>Choose from {$cdata['catname']}</option> "; foreach ($cdata['items'] as $row) { $tdata .= "<option value={$row['id']} data-em='{$row['em']}' data-gm='{$row['gm']}'>" . htmlspecialchars( $row["itemname"] ) . "</option>"; } $tdata .= "</select></td> <td class='em ca'>0</td> <td class='gm ca'>0</td> </tr> </tbody>"; } /******************************************************************************* * generate html for additional output row * * @param PDO $db * @param int $cat_id */ function tableItemRow(PDO $db, $cat_id) { $res = $db->prepare("SELECT id , itemname , em , gm , cat_name FROM item i JOIN category c USING (cat_id) WHERE cat_id = ? ORDER BY itemname "); $res->execute([$cat_id]); $opts = ''; $data = $res->fetchAll(); foreach ($data as $row) { $opts .= "<option value={$row['id']} data-em='{$row['em']}' data-gm='{$row['gm']}'>" . htmlspecialchars( $row["itemname"] ) . "</option>"; } $rowdata = "<tr> <td><select class='item-menu' name='item[]' onchange='item_menu_changed(this)'> <option value='' data-em='0' data-gm='0'>Choose from {$data[0]['cat_name']}</option>" . $opts . "</select></td> <td class='em ca'>0</td> <td class='gm ca'>0</td> </tr>"; return $rowdata; } ?> <!--#ffa500--> <!DOCTYPE html> <html lang='en'> <head> <title>sample</title> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type='text/javascript'> $().ready( function() { $(".addmore").click( function() { let cid = $(this).data("cat") $.get ( "", {"ajax":"newrow", "catid":cid}, function(resp) { $("tbody[data-cat="+cid+"]").append(resp) }, "TEXT" ) }) }) function item_menu_changed(menu) { // // update values in current row // let therow = $(menu).parent().parent() let em = parseInt($(menu).find("option:selected").data("em")) let gm = parseInt($(menu).find("option:selected").data("gm")) $(therow).find(".em").html(em) $(therow).find(".gm").html(gm) // // calculate totals // let totem = 0 let totgm = 0 $(".em").each(function(k,v) { totem += parseInt($(v).html()) }) $(".gm").each(function(k,v) { totgm += parseInt($(v).html()) }) $("#totem").html(totem) $("#totgm").html(totgm) } </script> <style type='text/css'> I did one of these when I realized I should be editing line 2 instead of removing it. I'm not positive what I should be entering as the $pdoConnect('code'); That may be all I have whoopsa-futzed now? When I reload it with what I think it should be Opera GX and Chrome say: With $pdo = pdoConnect('barands_code'); included FireFox loads a blank, white, page. Local WAMP says: Line 17 is just a } that matches up with and open {. Everything's all the same everywhere I'm trying to run it. This is the local WAMP's db the code I posted is from:
  11. The line numbers are moved forward because I added my db credentials directly to the file. https://nwdb.42web.io/barand_rocks/ (it's a free host, might have security certificate issues until it verifies.) Here's a video showing what I did to run it.
  12. I get this when I try to run Barand's code: Notice: Undefined index: em in index.php on line 77 Notice: Undefined index: gm in index.php on line 77 The error above repeats a bunch of times. The table displays on the page under the errors and the dropdown menu's populate but, of course since it can't find em and gm it doesn't do it's thing to the input fields. The em and gm columns and fields are there in the database. It finds everything else, the database is connected, it finds 'itemname' but not other fields in that same table. Line 77 is: $tdata .= "<option value={$row['id']} data-em='{$row['em']}' data-gm='{$row['gm']}'>" . htmlspecialchars( $row["itemname"] ) . "</option>"; The weird thing is if I press the add row button it adds a row and menu (it's slow to do it like it's struggling for some reason but works). The menu it adds populates the input fields correctly. How in the world is a row it's adding working but the row that displays by it self doesn't???? I tried sorting it out but I'm swinging blind.
  13. Yes. It is. Thank you! I tried so hard to get mac_gyver's suggestion to work, I'm sure it does work, but I wasn't able to get it working with a database no matter what I tried. I don't understand what the categories thing that keeps being mentioned is. I very much appreciate all the help and input, from everyone that attempts helping! To shorten my code I've resorted to making separate files out of each section: table_header.php <html> <head></head> <body> <table><tr><td> <table border="1" border-color="orange" id="items_table"><tr> <thead> <tr><th colspan="3" class="category_top">Items</th></tr> <th>Categories</th> <th> em</th><th>gm</th><th style="border:none;"></th> </thead> rifles.php <!-- Rifles --> <div> <tr><td colspan="3" class="categoryth"><span class="text">Rifles</span></td><td><button type="button">+</button></td></tr> </tr><tr> <td><select id="rmenu" name="selection"> <?php $data = $pdo->query("SELECT id, rifleName, em, gm FROM rifles ORDER BY id"); foreach ($data as $row) { echo "<option value={$row['id']} data-em='{$row['em']}' data-gm='{$row['gm']}'>" . $row["rifleName"] . "</option>"; } ?> </select></td> <td><!-- Rifle EM--><input class="cal_em" type="text" id="rem" value="0" disabled size="5"/></td> <td><!-- Rifle GM--><input type+"text" id="rgm" value="0" disabled size="5"/></td> </tr> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type='text/javascript'> $().ready(function() { $("#rmenu").change( function() { let em = $(this).find("option:selected").data("em") let gm = $(this).find("option:selected").data("gm") $("#rem").val(em) $("#rgm").val(gm) }) }) </script> <!-- End Rifles --> </div> shotguns.php <div> <tr><td colspan="3" class="categoryth">Shotguns</td><td><button type="button">+</button></td></tr> </tr> <tr><td> <select id="smenu" name="selection"> <?php $shotguns = $pdo->query("SELECT id, shotgunName, em, gm FROM shotguns ORDER BY id"); foreach ($shotguns as $row) { echo "<option value={$row['id']} data-em='{$row['em']}' data-gm='{$row['gm']}'>" . $row["shotgunName"] . "</option>"; } ?> </select> </td> <td><!--Shotgun EM--><input class="cal_em" type="text" id="sem" value="0" disabled size="5"/></td> <td><!--Shotgun GM--><input type="tect" id="sgm" value="0" disabled size="5"/></td> </tr> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type='text/javascript'> $().ready(function() { $("#smenu").change( function() { let em = $(this).find("option:selected").data("em") let gm = $(this).find("option:selected").data("gm") $("#sem").val(em) $("#sgm").val(gm) }) }) </script> </div> </tr> and so on.....I'm using includes to put it all together (example....this isn't the actual file it was one I grabbed quick to example): index.php <?php include ('secFol/c.php'); ?> <html> <head> <link rel="stylesheet" href="style/page.css"></link> <link rel="stylesheet" href="style/items.css"></link> </head> <body> <table border="0" width="100%"> <tr><td><?php include ('pages/rifles.php');?></td> <tr><td><?php include ('pages/bows.php');?></td> <tr><td><?php include ('pages/shotguns.php');?></td> <tr><td><?php include ('pages/optics.php');?></td></tr> </table> </body> </html> I understand and I'm thinking to myself doing it this way is only making it more difficult but my OCD gets upset if my code isn't nice, neat, organized, and as few lines as possible. I get bothered by having to scroll through a 90 mile long file of code that's the same thing (slightly different) over and over again. Awesome!! You got the totals working! Thank you! That was my next task I was probably going to have a hard time figuring out that I'll be asking about. The plus buttons I intend to duplicate each div so users can add an additional item of that type, because players often do that - buy more than one thing of each item type. That's another thing I'll be figuring out. I have a script that duplicates the div but...getting the totals to work with that, I assume, is going to be a difficult task for me to figure out on my own. I'll copy what you did and use it! Thank you so very much! And now I finally see what you and mac_gyver mean: item +----+---------------------+------+------+--------+ | id | itemname | em | gm | cat_id | +----+---------------------+------+------+--------+ | 1 | .308 Bolt action | 225 | 1350 | 1 | | 2 | 7mm magnum | 300 | 1575 | 1 | | 3 | .243 LeverAction | 215 | 8725 | 1 | | 4 | 6ft Longbow | 135 | 1120 | 2 | | 5 | 5ft Flatbow | 235 | 1345 | 2 | | 6 | Recurve | 215 | 2525 | 2 | | 7 | Purdy 12 bore | 135 | 1120 | 3 | | 8 | Beretta 12 bore | 235 | 1345 | 3 | | 9 | Small bore rook gun | 215 | 2525 | 3 | | 10 | Glock 9mm | 125 | 1050 | 4 | | 11 | Colt .38 | 200 | 1175 | 4 | | 12 | Derringer .22 | 115 | 3125 | 4 | +----+---------------------+------+------+--------+ category +--------+----------+ | cat_id | cat_name | +--------+----------+ | 1 | Rifles | | 2 | Bows | | 3 | Shotguns | | 4 | Pistols | +--------+----------+ I knew whatever you and mac meant was a better way of doing it. I wasn't translating what, exactly, you mean. This explains it! I can and will do that. I don't mind doing any amount of work if it results in things working better, and less code. I'll fix my .ods file and make a new database structure so it's like that. Thanks!
  14. I had my first experience with php in 1997. I consider myself an 'oldie' because I'm proud to share I was a member of the teams behind php-nuke CMS packages. I didn't do much coding, I don't and never did know much about the code. I did front-end, graphics, themes, created a module or two. I understood a lot about how those packages worked and was able to help people install, use, and modify their site. I was on the tech support teams on futurenuke, nukeplanet, and others. It was rewarding being able to help people. I'm curious. This domain has been around since somewhere around 1995-ish? It's always been a php reference and help site as far as I know. Is it the same group of people as it was in the late 90s, early 2000s?
  15. Result: Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ehr_bt.category' doesn't exist in C:\Program Files (x86)\EasyPHP-Devserver-17\eds-www\ehr_tracker\try13\mac_gyver1.php:26 Stack trace: #0 C:\Program Files (x86)\EasyPHP-Devserver-17\eds-www\ehr_tracker\try13\mac_gyver1.php(26): PDO->query('SELECT c.name, ...') #1 {main} thrown in C:\Program Files (x86)\EasyPHP-Devserver-17\eds-www\ehr_tracker\try13\mac_gyver1.php on line 26 I got Barand's suggestion to work. It just worked. I'll stick with using that. Thank you so much for the 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.