Jump to content
Larry Ullman's Book Forums

Recommended Posts

1. I removed the "forum.php" from line 115 (pls. see my code below) so that the page does not redirect to the "Forums" page when a new language selection is made. It works, but is this good coding practice and is there a better way to stop the page from redirecting?

 

// For choosing a forum/language:
echo '</b><p><form action="" method="get">
<select name="lid">
<option value="0">' . $words['language'] . '</option>
';

 

2. What changes do I have to implement to the code and database if I want only the languages (and not the word "Language") to appear in the selection field?

 

3. Is it possible to make the "Language" form to use the selected language simply by selecting it without requiring an input button, using php/html only? I couldn'd find anything on the web, except for a Javascript solution.

Link to comment
Share on other sites

I've never gone through Chapter 17 in the 4th edition, so I cannot comment on #1 and #2, but for #3, Javascript is the only way to make a language transition possible without the use of an input button.

Hopefully someone will comment on #1 and #2 for you.

Link to comment
Share on other sites

As for 1, it wasn't really a redirection, it was a form submission. Keep in mind the form will now always be submitted back to the current page, so every page that would show that form would have to have the code to handle a form submission. That code is already in the header, so it's safe, but just so you know.

 

As for 2, you would remove this line of code:

 

Link to comment
Share on other sites

Thank you Larry and Hartley for your very helpful responses.

 

I have 3 more questions if I may.

 

1. Would the language query still run okay if I moved the language form to the footer?

 

2. As there are database queries in my site's header, body and footer, can I establish the MySQL connection in the header and close it in the footer, and then just free the results after every query ran by the scripts, then remove all the database connections, where required by the other scripts (i.e. registration), if the header an footer are included?

 

3. I want to make the language form sticky, but the code (included below) doesn't work, although it works with the other select forms. Am I missing something obvious?

 

// Choose a language:
  echo '<form action="" method="get" id="language.form"><label for="lang">' . $words['language'] . '</label>
  <select name="lid">';
  // Retrieve all the languages:
  $q = "SELECT lang_id, lang FROM languages ORDER BY lang ASC";
  $r = mysqli_query($dbc, $q);
  if (mysqli_num_rows($r) > 0) {
   while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) {
 echo "<option value=\"$menu_row[0]\">$menu_row[1]</option>\n";
 // Make form sticky:
 if (isset($_POST['lang']) && ($_POST['lang'] == $menu_row[0]) ) echo 'selected="selected"';
 echo ">$menu_row[1]</option>\n";
   }
  }
  // Free the results:
  mysqli_free_result($r);

 

Thanks you in advance.

Link to comment
Share on other sites

1. Would the language query still run okay if I moved the language form to the footer?

 

The query would run fine but the site wouldn't work as many elements in the entire page need to know the language in use.

 

2. As there are database queries in my site's header, body and footer, can I establish the MySQL connection in the header and close it in the footer, and then just free the results after every query ran by the scripts, then remove all the database connections, where required by the other scripts (i.e. registration), if the header an footer are included?

 

Yes.

 

3. I want to make the language form sticky, but the code (included below) doesn't work, although it works with the other select forms. Am I missing something obvious?

 

Yes. The form uses GET and you're using POST to test for stickyness.

Link to comment
Share on other sites

Thank you for your response Larry. I managed to make the select form sticky - apart from my GET/POST error, I also incorrectly used 'lang' instead of 'lid' after the global. The 'stickyness' however disappears when a page is refreshed or a new page is loaded. How can I correct that?

Link to comment
Share on other sites

 Share

×
×
  • Create New...