Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. If there was, you would have found it or someone would have posted it. The design was overly complicated, so the solution would have been overly complicated too. You stated you wanted to do this in a simple way. Complicate and simple are mutually exclusive. The simple way turned out to be to fix the design, which probably made most of the code managing the different tables go-a-way and made the code for the current task simple.
  2. In general, this is achieved by using a template/database driven design. Based on the country/language selected, you retrieve the correct content from the database and populate the sections of the template. Then someone fluent in one of the possible languages is responsible for creating and maintaining the blocks of content to make sure that they are grammatically correct in that language. For the large multi-national company you linked to as an example, this is easy because they simply have someone in an office in each country responsible for creating and maintaining the content for that country. So, no there are no tools to take a general web page and convert it to this format. The page must be coded from the ground up 'like' a database driven CMS, than add the language/country selection logic to cause the appropriate content to be retrieved and output on the page.
  3. The two that use the same connection information are actually the same connection and would use the last selected database on that connection, unless you specify a TRUE value for the 4th parameter in the mysql_connect statement.
  4. You have a third party script that is either - A) Missing some code (or it's not being seen as being code) that would have defined the missing objects, which means that you won't get it to actually work just by 'fixing' each of these current errors, because there is more missing than is what is causing these current errors, or B) It is a poorly written script that always produced these errors, but they were being hidden by php's error_reporting/display_errors settings. In fact, this is a purchased copyrighted script that you cannot post here (I have edited your posts to remove the complete code). You should contact the author for support. Also, moving this thread to the third party script forum section.
  5. If you are getting a HTTP 500 Internal Server Error on a .php page it usually means that you are getting a fatal parse or a fatal runtime error. You should be developing and debugging your code with php's error_reporting set to E_ALL and display_errors set to ON, so that php will report and display all the errors it detects. The snippet of posted code doesn't produce a fatal parse error. We cannot possibly help you with a HTTP 500 Internal Server Error without A) the code for the entire page, including any included/required files (less any database connection information) and B) the php detected errors on the page.
  6. For a function definition, the statements between the opening and closing braces { ... } are the code for that function definition. function PostInformation() { // statements that are part of this function definition go here... } You would need to move the closing } down so that it is after all the statements you intended to be inside that function definition.
  7. The query is empty because the php variable, $sql, being put into the mysql_query() statement, near the end of your posted code, doesn't exist in the program scope where the mysql_query() statement is at. Your PostInformation() function definition ends immediately after the assignment statement for the $sql variable. It should end after the echo "1 record added"; statement.
  8. http://en.wikipedia.org/wiki/Comma-separated_values#Basic_rules_and_examples
  9. You need to set php's error_reporting to E_ALL and display_errors to ON to get php to help you find problems. While the error message you would have been getting - Warning: mysql_num_rows() expects parameter 1 to be resource, object given in ... isn't explicitly telling you that you need to use the mysqli statement, it would have been calling your attention to that statement and throwing an error where normally there would not be an error.
  10. YOu cannot mix mysqli (with an i) and mysql (no i) statements on the same connection. You would need to use mysqli_num_rows (with an i). Edit: and mysqli_connect() lets you specify the database as the 4th parameter.
  11. I was going to try and get the example code posted above to work with your existing table definition, but I decided that would be too much work. You need to fix your database design to be able to use code like that. To avoid repeating the actual data (myPageURL, myButtonTitle, myTitle) you should actually have one more table the Relates (the R in RDBMS) the menu choices with the actual data for the menu item.
  12. Only part of line 15 should have been changed. The code you found/learned... is over 10years out of date, it also isn't validating anything so I hope you are not going to put this on a live web server where spammers can find it and send their email through your mail server.
  13. Here's (untested) code that does what I suggested above - <?php // build navigation // use an array to map your 'type' number to the css class name $map = array(1=>'top',2=>'middle',3=>'side',4=>'footer'); // your posted code used 'side' for #1 and #3, which I doubt is what it really is $query = "SELECT id, type, myPageURL, myButtonTitle, myTitle FROM myPageData WHERE myPageActive='Yes' ORDER BY type,listorder"; $result = mysql_query($query); $navigation = array(); if(mysql_num_rows($result) > 0){ $last_type = null; while($row = mysql_fetch_assoc($result)){ $type = $row['type']; // copy to scaler variable, used several times if($last_type != $type){ // the type changed, either a new one or the first one if($last_type != null){ // not the first one, close out the previous section here... $navigation[$last_type] .= "</ul>"; } // start a new section here... $navigation[$type] = "<ul class='mm-{$map[$type]}-ul'>"; // remember the new type $last_type = $type; } // output (build) the data under each section here... $id = $row['id']; $myPageURL = $row['myPageURL']; $myButtonTitle = $row['myButtonTitle']; $myTitle = $row['myTitle']; $navigation[$type] .= "<li class='mm-{$map[$type]}-ul-li'><a href='$id.$myPageURL.html' title='".$myTitle."'>".$myButtonTitle."</a></li>"; } // close out the last section, if any, here... if($last_type != null){ $navigation[$last_type] .= "</ul>"; } } You would use the result of the above code by echoing the correct element of the $navigation array where you want it - <?php /* TOP NAVIGATION */ echo isset($navigation[1]) ? $navigation[1] : ''; ?> <?php /* LEFT NAVIGATION */ echo isset($navigation[3]) ? $navigation[3] : ''; ?> <?php /* FOOTER NAVIGATION */ echo isset($navigation[4]) ? $navigation[4] : ''; ?> There's another benefit of reducing all the repetitive code, you make less mistakes when copy/pasting/over-typing it for each section. Also, any markup/formating appears only once so you only have one place to change when you want to modify the style on your page.
  14. If you really want to simplify your code, you need to - 1) Eliminate the four myPageNav1,2,3,4 columns, and have just one 'type' column that holds the correct 1,2,3,4 value. 2) Execute one query that gets all the rows you want in the order that you want them. You would order by the 'type' column and the listorder column. 3) loop over the rows the query retrieves and build each navigation section in a different php variable (actually an array, using the type as the array index so that the code will be universal.) 4) Simply echo the appropriate array section where you want it in the html markup on your page.
  15. Your session_start() statement must come before any reference to a $_SESSION variable. While you can use a session variable to prevent accidental resubmission of data, you cannot use it to prevent intentional resubmission of data because all it takes to get a new chance is to drop the session id cookie and you get a new session.
  16. Sample code that demonstrates how simple your 'cart' and code should/can be - <?php session_start(); // if the cart does not exist, create an empty cart if(!isset($_SESSION['cart'])){ $_SESSION['cart'] = array(); } // fake adding items to the cart for demo purposes $_SESSION['cart'][1] = 3; // id = 1, qty = 3 $_SESSION['cart'][2] = 1; // id = 2, qty = 1 // lists only the id/qty in the cart function list_cart($cart){ if(empty($cart)){ echo "Your cart is empty! <br />"; } else { foreach($cart as $id=>$qty){ echo "Product Id: $id, Quantity: $qty<br />"; } } } list_cart($_SESSION['cart']); // example usage, pass the actual cart into the function as a call-time parameter Some notes about this code - 1) The 'cart' should be passed into the function, as shown, as a call-time parameter so that the 'cart' can come from anywhere, a session, a database query, a cookie, xml, ... 2) I named the function list_cart because that's all it does. To actually display all the information about the contents in the cart, you would extract the id's (using array_keys), use ONE query, not in a loop, to get the product information for all those product id's, store that product information into an array, again using the product id as the key to that array, then as you loop through the contents of the 'cart' you would use the product id from the cart to reference the product information for that id. 3) The variable names and array index names indicate the meaning of the data in the variables.
  17. If you make the change I suggested, you don't have to target specific keys. All the 'cart' related keys/values will be in $_SESSION['cart']. All the references to $_SESSION that are part of the 'cart' logic just need to be changed to $_SESSION['cart']. Edit: Also, I would add that the definition of that cart, where you are using " product_'productid' " is overly complicated. You have probably 2-3 times more code than needed for every function that references the cart. Just use the product id as the key and store the quantity as the value, and if the quantity is zero, just remove the entire key/value from the cart.
  18. The tutorial you found is, what would be a polite phrase, 'technically challenged'. The cart stored in the session should be stored in a unique session variable like $_SESSION['cart'], not in $_SESSION. This would separate any data for the cart from data for other purposes.
  19. while ($iRow = $iResult->fetch_row()) { $array[$iRow[0]] = $iRow[1]; }
  20. For your existing code to work, the execution of the query would need to be inside the loop. It's apparently outside of and after the end of the loop. Since it is not inside of the loop, best guess is your $category[0] value isn't what you expect and the loop is being skipped over. There's a couple of problems with what you are doing. 1) You shouldn't execute a query inside of a loop. For inserting multiple rows, there's a mulit-value insert query. 2) You shouldn't need to carry around a count of the number of items in a form, because you should use an array(s) for the form fields, which would let you use php's array functions to iterate over the submitted form data. The snippet of code you posted doesn't show us enough information to help further, either with the error you got or with the things I mentioned.
  21. Since the id and the item are directly related to each other, why not use the id as the array index and the item as the array value. That gives one array holding all the related data.
  22. Your submitted month and day don't have leading zeros (you also have a typo in your day dropdown at the 30th day) so the hyphen separator character would be required for the database to be able to figure out the actual date.
  23. Here's a start... Part B - if(isset($_POST['submit'])){ // note: you will need a field in your form with a name='submit' attribute // the rest of your form processing code goes here... }
  24. A) Form processing code should be in your logic before the code that displays the form so that the updates will be shown when the form is redisplayed. B) Form processing code should also test if a form as been submitted so that it only runs when there is data from the form. C) Since checkboxes that are not checked aren't set in the submitted form data, you will need a way of determining which id's in your database table should be cleared and which should be set. I would first retrieve all the id's from your table, just the id's, and place them into an array. Then use array_diff between the array of all the id's and the $_POST['places'] array of checked id's. This will give you an array of the id's that are not checked and the $_POST['places'] array is an array of the id's that are checked. Next you would implode, using a comma as a separator, those two arrays, so that you can use them in an IN() comparison in a WHERE clause in UPDATE queries. Run one UPDATE query using the imploded array of unchecked id's in the WHERE clause to SET the enabled field to a zero and run a second UPDATE query using the imploded array of checked id's in the WHERE clause to SET the enabled field to a one. Rows where the UPDATE value is the same as the existing value actually aren't updated.
  25. Also, for the version using HAVING, you would only put the newDate condition in the HAVING clause. You would still use a WHERE clause for the other condition.
×
×
  • 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.