Jump to content
Larry Ullman's Book Forums

Wagtail

Members
  • Posts

    136
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Wagtail

  1. Hi everyone, I'm really having trouble with a query. The query needs to loop out all of the rooms and amenities of a particular hotel. This wasn't a problem until I added an intermediary table. Because the hotel ID appears X amount of times in the intermediary “hotels_features” table, the rooms and amenities will loop out X amount of times, instead of only once. I am not sure if the query is the problem or what. In the code I've posted I only included a while loop for the rooms. Please assist me with this if you can. Thank you very much. $q = "SELECT column names FROM hotels AS h INNER JOIN rooms AS r ON r.hotel_id=h.hotel_id INNER JOIN hotels_features AS hf ON hf.hotel_id = h.hotel_id INNER JOIN features AS f ON f.features_id = hf.features_id ...WHERE category = '$category'"; $r = @mysqli_query($dbc, $q); $row = mysqli_fetch_array($r, MYSQLI_ASSOC); // echo data here $r2 = @mysqli_query ($dbc, $q); while ($row2 = mysqli_fetch_array($r2, MYSQLI_ASSOC)) { // loop content here } // continuing echoing data here
  2. Ok, thank you Larry. I see that this thread has been viewed 1,580 times. Is this accurate?
  3. HartleySan, thank you for your help. I have not yet been able to test the scripts but will let you know as soon as I have done so. Thanks!
  4. Hi Antonio, thank you for getting back to me. I know how use foreach loops but don't know how to use the loops to check that all $_POST['employees'] and all $_POST['computers'] have values bigger than 0 before the form can be submitted. It is the combining of the foreach loops and the checking of values bigger than 0 that is giving me trouble. All of the stores come from a database. I might have a page with 10 stores, each store having an employee and a computers select menu. A website visitor can select one or more stores, and for each store selected both select menus must have values bigger than 0 before form submission can occur. And for each store's select menus I've included the store's name in the name attribute, so that I can access the store's name on the receiving page. Sorry to trouble you with this, but maybe someone can help me figure this out. I appreciate your help!
  5. Morning guys, I am sorry but I haven't got the foggiest idea how to integrate the foreach loops with the code that HartleySan provided. And I've been at it for a few hours. Could you please provide me with an example of how to do this? I don't know if this is relevant but the receiving page needs to receive the values in such a manner so that I can access both the keys and the values for each store. This is because I'm printing out each store name (which is the key) and underneath the values of the two select menus. The foreach loop I've used just sent the values to the receiving page so I couldn't access the key. Thank you again.
  6. Hi Antonio, thank you very much for your assistance. I will try that. I am using the name of the stores as keys, hopefully it will still work. I hope you and HartleySan are both well. Cheers <select name="employees['.$row['store_name'].']">'; <select name="computers['.$row['store_name'].']">';
  7. Thanks a lot HartleySan! Do you think it will be difficult to adapt this validation for data coming from a database? It occurred to me that I won't know beforehand which stores will be displayed or how many values each select menu might have.
  8. Hello forum members, I am struggling with the validation for the following select menus. Each store has 2 select menus, one for number of computers and one for number of employees. A user must select at least one store, and both select menus of that particular store need to have values greater than 0 before the form can be submitted. If more than one store is selected, then again, both select menus of those stores need to have values greater than 0. How do I begin with this validation? Please help me. Thank you. <select class="computers" name="computers[store1]"><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option></select> <select class="employees" name="employees[store1]"><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option></select> <select class="computers" name="computers[store2]"><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option></select> <select class="employees" name="employees[store2]"><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option></select>
  9. Yes, thank you. I appreciate you getting back to me so quickly on this. The one form method sounds like a good idea. Thanks for your help! Ciao
  10. Perhaps I haven't explained myself properly. I know that I can validate data sent via POST. When I first created my form, the only inputs were for the datepicker. If someone selected a date he/she could submit the form and it would go to the next page. The form had action="page2.php" method="post", and I didn't validate the information. But in order to ensure that the form wasn't submitted without a date, I had to add some validation. Towards the end of the validation code I had: if ($startdate && $enddate) Now clearly something has to happen after this code - the form must be submitted with the values and in my case be redirected to another page. What I meant above was that without validation I could submit the form and the values would be sent with the POST method, but with validation I need to use the header: location function, and the GET method.
  11. Thanks, some things to consider. I'll probably go with the hidden input values for the second form. It's strange that I can post the form values to another page if I don't use validation, but with validation I'm forced to use the GET method by appending the values to the location URL. Or am I missing something?
  12. Hi HartleySan, thanks for responding. On one of my pages I'm using a datepicker and the selected dates need to sent to another page. And on that other page I have another form whose selected values, together with the datepicker values, need to be sent to another page. It's a type of checkout setup. The only data I'm sending along are dates and quantities, so no sensitive information really
  13. Hi all, I came across this post and have a question about using header('Location:). One of my forms posts data to another page. After I have validated the inputs, I then include the header function which has a query string appended to the URL. Is this an acceptable means of sending form values to another page? I think I read somewhere that some servers have a problem with this - or maybe not, I cannot remember. Is there another way to send the form values to a different page? Thank you for your time!
  14. Thank you for getting back to me HartleySan. Just one question. Before I make the query to update the database, there is a condition to check if the variables are true: if ($name && $oq ) But if I set $oq to NULL then that variable is false, which means I can only assign an empty string or 0 to $oq in order for the condition to be true. Is that correct? Thank you!
  15. Hi everyone, Happy New Year! Could someone please help me with the following? I'm using a form to update a database table but I'm not sure what to do with values that are optional/not required. Do I set the value to NULL? Also, should I validate any text inputs with FILTER_SANITIZE_STRING? Thank you in advance! // Check if the form has been submitted: if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); // Trim all the incoming data: $trimmed = array_map('trim', $_POST); // Assume invalid values: $name = $order_quantity = FALSE; // Check for a name: if (empty($_POST['name'])) { $errors['name'] = 'You forgot to enter your name.'; } else { $name = mysqli_real_escape_string($dbc, $trimmed['name']); } // Check for the order quantity: if (filter_var($trimmed['order_quantity'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $oq = mysqli_real_escape_string ($dbc, $trimmed['order_quantity']); } else { $oq = NULL; } if ($name && $oq ) { // If everything's OK... // Make the query: $q =”UPDATE....
  16. Hey HartleySan, how you doing? Thank you for clarifying this. Of course it would be much easier changing a name in one place instead of in multiple places. Looks like I missed that. So separate tables it is then! Cheers
  17. Hi HartleySan, thanks for your assistance. I am going to leave this checkbox stuff for the moment and concentrate on other parts of the website.
  18. Hello Antonio, thank you for your thoughtful response. I like your proposal of implementing a hybrid solution - perhaps I can have one column in the museum table that lists all of the location details and still have the foreign keys as usual. One thing I can't understand is why separate tables are necessary to filter or sort the information. If I need to find all museums in Canada, and I have the actual country name in the museum table, won't it then return those specific records? You asked me about my uses cases. Well, for now I'm attempting to use the checkboxes to sort/filter the records. That is if I manage to get them working. I'll probably end up using something like an autocomplete as well. Thanks again for your help.
  19. Hi everyone, having read the chapter on database design, I have a few questions about how to normalize my database. Lets say I have a website about all of the museums in the world - what would be the best way to store location information? Can I have columns for city, region, country and continent all in one table, as below? museum_id museum_name city_name region_name country_name continent_name other columns with foreign keys I did have separate tables for each of the location columns but it becomes exceedingly difficult if I have a table with 500 museums and multiple columns with foreign keys. Using phpMyAdmin it isn't easy to see what's going on if I have rows consisting of many numbers. Isn't this confusing? In chapter 6, Database Design, there is a publishers table on page176 which also has all of the location (address) information in the same table. Are there any advantages/disadvantages to having the location columns in the same table vs separate tables with regards to SEO or the ability to sort/filter/search the contents of the table? By the latter I mean when a website visitor uses the website's checkboxes/autocompletes or text inputs to find/filter information. One benefit to having separate location tables might be when it is necessary to include extra information pertaining to a specific region or city, such as attractions or accommodation types. Thank you!
  20. Sorry, by this I meant to say that the script has to work with JavaScript disabled before I can add the Ajax functionality.
  21. Hi, I have tried setting $start to 0 but it didn't work. Where exactly should I put this? Putting $start = 0 directly after if (isset($string)) didn't work. I first need to get the checkboxes working with PHP before I can try the Ajax.
  22. Hi HartleySan, I have been “echoing out” the variables and the problem seems to be the $start and $_GET['s'] variables. When a checkbox has been selected, the page will load and display a certain number of pagination links (numbers) depending on the total number of results. I now click to page 4 (as an example). On page 4, I select another checkbox and load the page. The page will load but will display the same current pagination link as before I selected a new checkbox. The $_GET['s2'] variable already has a value of 4 and so this value is assigned to the $start variable. I don't know if I can use a loop to say that every time the $string variable is set the below code will run from the beginning again. // Determine where in the database to start returning results... if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } Will keep on trying. Thank you for your help.
  23. Hi Antonio, thanks for helping. I did post the origins of the $string variable in an earlier post. The contents of the $string variable are created when one or more checkboxes are selected. I have tried various things but to no avail. It must have something to do with how $start2 is set. $arguments =''; if (isset($_POST['hobby'])){ foreach ($_POST['hobby'] as $k) { $arguments[] .= "hobby='$k'"; } } if (isset($_POST['income'])){ foreach ($_POST['income'] as $a) { $arguments[] .= "income='$a'"; } } if(!empty($arguments)) { $string = implode(' && ',$arguments); }
×
×
  • Create New...