Jump to content

Adamhumbug

Members
  • Content Count

    212
  • Joined

  • Last visited

Everything posted by Adamhumbug

  1. When i do the following: while ($stmt -> fetch()) { $user =[$role, $fn, $ln, $id]; } i only get one result and i know the sql is pulling 3 results. I tried using .= but that give me an array to string error.
  2. Hi All, I have a select statement $stmt = $conn -> prepare(' SELECT u.user_firstname, u.user_lastname, so.staff_id, r.role_name FROM ssm_staff_order so INNER JOIN ssm_user u on so.staff_id = u.user_id INNER JOIN ssm_role r on u.user_role_id = r.role_id WHERE job_id = ? '); $stmt -> bind_param('i', $jid); $stmt -> execute(); $stmt -> bind_result($fn, $ln, $id, $role); The result looks like this +----------------+---------------+----------+-----------+ | user_firstname | user_lastname | staff_id | role_name | +----------------+---------------+----------+-----------+ | FName | LName | 8 | Chef | | jon | smith | 15 | Manager | | Chelsea | Hockley | 2 | Manager | +----------------+---------------+----------+-----------+ I am wanting to build an array so that i can foreach the result with the people under the header of their role. I know this is not difficult but i am going around and around with it and clearly missing the key part. As always your help is appreciated.
  3. A bit of working out here but that worked perfectly. Thank You
  4. I have an array that has comma sep values. I am wanting to run a select statement that includes a NOT IN function. SELECT user_firstname, user_lastname, user_id FROM ssm_user WHERE user_role_id = ? and where user_id NOT IN(?) Is this possible, oir does the ? just represent a literal string. If so do i need to convert the array to a string before running the above?
  5. I think i have answered my own question about 10 seconds after posting this. if(!empty($_SESSION['message'])){ doesnt seem to generate the same message that if($_SESSION['message'] !=''){ did Thanks anyway
  6. I have a message bar that when a page reloads, a message appears at the top of the screen. I feed the message with session variables that are set at the end of the action (submission for example) When the page reloads the message displays and then unsets the session variables. The issue is when the page first loads (when it has never run an action) and gives me the Notice: Undefined index: message. My question is, how can i handle the session being blank when the page first loads and thus not get the notice.
  7. <a onclick='delModal($miid);' data-toggle='modal' href='#delConfModal' data-id='$miid' class='delButton btn btn-danger'>Delete Menu Item</a> seems to be working
  8. i think i have corrected this by passing the menu item id in the function call
  9. undefined - the button has a data ID though and i am trying to get it in the same way as on the other ajax.
  10. No it hasnt changed anything having the quotes in there.
  11. ajax=two is getting sent but nothing else
  12. It is now showing the response which is nice. I am however getting Undefined index: id on the switch calling the second function.
  13. ahhhh, and i thought i was doing so well. Ok ill have another look at resorting it. I have chnaged the function to just be a function rather than looking for a click. I have put an onclick on the button that is being created.
  14. No i am pretty sure it runs after - i think i have pretty much duplicated what i have done to make the first modal. Here is everything for context. <?php if (session_status() == PHP_SESSION_NONE) { session_start(); } if (!isset($_SESSION['user_id'])){ header("location: index.php"); exit; } //name of the pagea $_SESSION['this_page'] = 'new-menu'; include '_includes/dbconn.php'; function getMenuItems($conn){ $output = ''; $stmt = $conn -> query(" SELECT menu_category_name FROM ssm_menu_items INNER JOIN ssm_menu_category on menu_item_category_id = menu_category_id ORDER BY menu_category_display_order "); //create an empty array of all of the menu categories that are in use foreach ($stmt as $item){ $menuItemsInCat[$item['menu_category_name']] = []; } $stmt = $conn -> prepare(" SELECT menu_item_id, menu_item_name, menu_category_name, sum(menu_item_qty) FROM ssm_menu_items mi INNER JOIN ssm_menu_category mcat ON mi.menu_item_category_id = mcat.menu_category_id left join ssm_menu_order USING (menu_item_id) GROUP BY menu_item_id "); $stmt -> execute(); $stmt -> bind_result($miid, $miname, $mcatname, $miqty); while ($row = $stmt -> fetch()) { //put items into the blank array created above under their correct category $menuItemsInCat[$mcatname][$miid] = [$miname, $miqty]; } //foreach thing in $menuItemInCat array there is $menucat array associated with $menuit(ems) array //we want the menu cat foreach ($menuItemsInCat as $menucat => $menuit) { $output .= "<tbody>"; $output .= "<tr class='bg-secondary text-white text-center'><th>$menucat</th>"; $output .= "<th>Qty On Order</th><th>Manage</th></tr>"; //foreach thing in menu items array there is an array of ids and an array of items foreach ($menuit as $itemId => $itemName) { $output .= "<tr><td>$itemName[0]</td>"; $output .= "<td>$itemName[1]</td>"; $output .= "<td><div class='modaltrigger btn btn-primary' data-id='$itemId' data-toggle='modal'>Manage</div></td></tr>"; } $output .= "</tbody>"; } return $output; } //handle ajax if(isset($_POST['ajax'])){ switch ($_POST['ajax']) { case 'one': exit(popManageMenuModal($conn, $_POST['id'])); break; case 'two': exit(popConfDelModal($conn, $_POST['id'])); break; } } function popConfDelModal($conn, $miid){ $out = ""; $out .= "<div>This is some info</div>"; return $out; } function popManageMenuModal($conn, $miid){ $stmt = $conn -> prepare(' SELECT menu_item_name, menu_item_is_vegan, menu_item_is_vegetarian, menu_item_is_gf, menu_item_is_nf, menu_item_is_df, menu_item_category_id FROM ssm_menu_items INNER JOIN ssm_menu_category on menu_item_category_id = menu_category_id WHERE menu_item_id = ? '); $stmt -> bind_param('i', $miid); $stmt -> execute(); $stmt -> bind_result($miname, $miisvegan, $miisveg, $miisgf, $miisnf, $miisdf, $mcatid); $stmt -> fetch(); $output = ""; $output .= "<form><div class='modal-body'><div class='form-group'><label >Menu Item Name</label><textarea name='menuItemName' class='form-control'>$miname</textarea></div>"; $output .= "<div class='form-inline'><input name='miid' type='hidden' value='$miid'>"; $a = array('Vegan'=>$miisvegan, 'Vegetarian' => $miisveg, 'Gluten Free' => $miisgf, 'Nut Free' => $miisnf, 'Dairy Free' => $miisdf); foreach ($a as $type => $value) { if($value == '0'){ $polarity = 'btn-danger'; } if($value == '1'){ $polarity = 'btn-success'; } $output .= "<div class='m-1 col drButton btn {$polarity}' data-value='$value'>$type</div><input id='$type' type='hidden' value='$value' name='$type'>"; } $output .= "</div>"; $stmt -> close(); $cat = $conn -> prepare('SELECT menu_category_id, menu_category_name FROM ssm_menu_category'); $cat -> execute(); $cat -> bind_result($menucatid, $mcatname); $output .= "<select name='menucategory' class='form-control mt-3'>"; $selected =''; while($cat -> fetch()){ if($mcatid==$menucatid){ $selected = 'selected'; }else{ $selected = ''; } $output.= "<option {$selected} value='$menucatid'>$mcatname</option>"; } $output .= "</select>"; $output .= "<div class='modal-footer'><a data-toggle='modal' href='#delConfModal' data-id='$miid' class='delButton btn btn-danger'>Delete Menu Item</a> <button formmethod='post' type='submit' class='btn btn-primary'>Save Changes</button> </div>"; $output .= "</form>"; return $output; } // handle post request if ($_SERVER['REQUEST_METHOD']=='POST') { $miid = $_POST['miid']; $miname = $_POST['menuItemName']; $vegan = $_POST['Vegan']; $vegi = $_POST['Vegetarian']; $gluten = $_POST['Gluten_Free']; $nut = $_POST['Nut_Free']; $dairy = $_POST['Dairy_Free']; $cat = $_POST['menucategory']; $stmt = $conn -> prepare(" UPDATE ssm_menu_items SET menu_item_name = ?, menu_item_is_vegan = ?, menu_item_is_vegetarian = ?, menu_item_is_gf = ?, menu_item_is_nf = ?, menu_item_is_df = ?, menu_item_category_id = ? WHERE menu_item_id = ? "); $stmt -> bind_param('siiiiiii', $miname, $vegan, $vegi, $gluten, $nut, $dairy, $cat, $miid); $stmt -> execute(); } function messageBar(){ global $miname; if($miname !=''){ $out = "<div id='messageBar' class='alert alert-success text-center'>{$miname} has been updated</div>"; return $out; } } ?> <?php include '_includes/head.php'; ?> <div class="container-fluid"> <div class="row"> <?php include '_includes/header.php'; ?> </div> <div class="row" > <div class="col-sm-2 p-0 bg-dark text-light"> <?php include '_includes/nav.php'; ?> </div> <div class="col-sm-10" style="height: calc(100vh - 80px);overflow:scroll;"> <div class="mt-3"> <?= messageBar() ?> <table class="table table-striped table-hover table-bordered text-center align-middle"> <?= getMenuItems($conn) ?> </table> </div> <div class="col-sm-12"><?php include '_includes/footer.php'; ?></div> </div> </div> </div> <!-- modal --> <div class="modal fade" id="manageMenuItemModal"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">Manage Menu Item</h4> <button type="button" class="close" data-dismiss='modal'>&times;</button> </div> <div id="menuItemInfo" class="container"> <!-- modal information will go here --> </div> </div> </div> </div> <!-- modal --> <div class="modal fade" id="delConfModal"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">Delete Menu Item</h4> <button type="button" class="close" data-dismiss='modal'>&times;</button> </div> <div id="delConfInfo" class="container"> <!-- modal information will go here --> </div> </div> </div> </div> <script> //set sidebar active indicator //XX = name of parent if in dropdown eg "sheet" if(document.getElementById('menu')){ document.getElementById('menu').classList.add('show') } //nav button ID if(document.getElementById('newMenu')){ document.getElementById('newMenu').classList.add('blOrange') } $('.modalTrigger').click(function () { var menuItemId = $(this).data("id") $.ajax({ type: 'post', data: {ajax : 'one', id: menuItemId}, success: function(response){ $('#menuItemInfo').html(response) } }) $('#manageMenuItemModal').modal({ show: true }) }) $('.delButton').click(function () { var menuItemId = $(this).data("id") console.log('one') $.ajax({ type: 'post', data: {ajax : 'two', id: menuItemId}, success: function(response){ console.log('i ran') $('#delConfInfo').html(response) } }) $('#delConfModal').modal({ show: true }) }) //dietary requirement buttons polarity $(document).on('click','.drButton', function(){ var polarity = $(this).attr("data-value") var id = $(this).text() var hi = document.getElementById(id) if(polarity == '0'){ $(this).addClass("btn-success") $(this).removeClass("btn-danger") $(this).attr("data-value", "1") if(hi){ hi.value = '1' } return false } if (polarity == '1'){ $(this).addClass("btn-danger") $(this).removeClass("btn-success") $(this).attr("data-value", "0") if(hi){ hi.value = '0' } return false } }); $('#messageBar').delay(2000).fadeOut(1000); $(document).ready(function () { $(document).on('show.bs.modal', '.modal', function (event) { var zIndex = 1040 + (10 * $('.modal:visible').length); $(this).css('z-index', zIndex); setTimeout(function() { $('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack'); }, 0); }); }); </script>
  15. <a data-toggle='modal' href='#delConfModal' data-id='$miid' class='delButton btn btn-danger'>Delete Menu Item</a> This is the button that calls the second ajax, it is an A tag so i can stack the modals
  16. ok, so i have created $out by putting $out =""; on the line above. The del button is coming from the modal that was created by the first function. I have put a console log into both ajax calls and can confirm that the second is not running.
  17. I am trying to work with this but the second modal is not getting the data from the second ajax call. if(isset($_POST['ajax'])){ switch ($_POST['ajax']) { case 'one': exit(popManageMenuModal($conn, $_POST['id'])); break; case 'two': exit(popConfDelModal($conn, $_POST['id'])); break; } } function popConfDelModal($conn, $miid){ $out.= "<div>This is some info</div>"; return $out; } function popManageMenuModal($conn, $miid){ The second function that i have cut off at the bottom is actually the one that runs first and works just fine. It is the popConfDelModal that doesnt output anything. This is the ajax $('.modalTrigger').click(function () { var menuItemId = $(this).data("id") $.ajax({ type: 'post', data: {ajax : 'one', id: menuItemId}, success: function(response){ $('#menuItemInfo').html(response) } }) $('#manageMenuItemModal').modal({ show: true }) }) $('.delButton').click(function () { var menuItemId = $(this).data("id") $.ajax({ type: 'post', data: {ajax : 'two', id: menuItemId}, success: function(response){ $('#delConfInfo').html(response) } }) $('#delConfModal').modal({ show: true }) }); and here is the html for the modals that you probably dont need to see. <div class="modal fade" id="manageMenuItemModal"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">Manage Menu Item</h4> <button type="button" class="close" data-dismiss='modal'>&times;</button> </div> <div id="menuItemInfo" class="container"> <!-- modal information will go here --> </div> </div> </div> </div> <!-- modal --> <div class="modal fade" id="delConfModal"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">Delete Menu Item</h4> <button type="button" class="close" data-dismiss='modal'>&times;</button> </div> <div id="delConfInfo" class="container"> <!-- modal information will go here --> </div> </div> </div> </div> Your help is always appreciated.
  18. This is what i thought would be the best option, just wanted to check.
  19. Hi All, Not sure if this is a silly question so here we go. I have some divs that have data attributes (data-value). When i submit and post the form, can i use these values as part of the submission and put their data-value into the db? Thanks as always in advance.
  20. This sorted me out $a = array('Vegan'=>$miisvegan, 'Vegitarian' => $miisveg, 'Gluten Free' => $miisgf, 'Nut Free' => $miisnf, 'Dairy Free' => $miisdf); foreach ($a as $type => $value) { if($value == '0'){ $polarity = 'btn-danger'; } if($value == '1'){ $polarity = 'btn-success'; } $output .= "<div class='m-1 col drButton btn {$polarity}' data-value='$value'>$type</div>"; }
  21. Hi All, I have a page where people can enter the name of food, like you would order in a restaurant (would appear on the menu). They can set if the food is gluten free, nut free, vegan etc. I am wanting to use buttons that can be clicked going red if they are not gluten free or not vegetarian and green if they are vegan or vegetarian. I have working code that does this but i dont feel like i am being efficient with how i am writing it as it is turning into a lot of repeated code. I would appreciate some help pointing me in the right direction. function popManageMenuModal($conn, $miid){ $stmt = $conn -> prepare(' SELECT menu_item_name, menu_item_is_vegan, menu_item_is_vegitarian, menu_item_is_gf, menu_item_is_nf, menu_item_is_df FROM ssm_menu_items WHERE menu_item_id = ? '); $stmt -> bind_param('i', $miid); $stmt -> execute(); $stmt -> bind_result($miname, $miisvegan, $miisveg, $miisgf, $miisnf, $miisdf); $stmt -> fetch(); if($miisvegan == '1'){ $vegansel = 'btn-success'; $vegan = 'Vegan'; $veganop = 'Is'; }else{ $vegansel = 'btn-danger'; $vegan = 'Vegan'; $veganop = 'Not'; } if($miisveg == '1'){ $vegsel = 'btn-success'; $vegi = 'Vegi'; $vegop = 'Is'; }else{ $vegsel = 'btn-danger'; $vegi = 'Vegi'; $vegop = 'Not'; } $output = ""; $output .= "<form><div class='form-group'><label>Menu Item Name</label><textarea class='form-control'>$miname</textarea></div>"; $output .= "<div class='form-inline'>"; $output .= "<div class='drButton btn $vegansel' data-value='$miisvegan'>{$veganop} {$vegan}</div>"; $output .= "<div class='drButton btn $vegsel' data-value='$miisveg'>{$vegop} {$vegi}</div>"; $output .= "<div>$miisvegan, $miisveg, $miisgf, $miisnf, $miisdf</div>"; $output .= "</form>"; return $output; } $(document).on('click','.drButton', function(){ var polarity = $(this).data("value") if(polarity == '0'){ $(this).addClass("btn-success") $(this).removeClass("btn-danger") $(this).data("value", '1') return } if (polarity == '1'){ $(this).addClass("btn-danger") $(this).removeClass("btn-success") $(this).data("value", '0') return } });
  22. Second question, what is the "TEXT" for?
×
×
  • 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.