Jump to content

roopurt18

Staff Alumni
  • Posts

    3,746
  • Joined

  • Last visited

    Never

Everything posted by roopurt18

  1. I'm not sure that IE6 likes multiple classes. Be warned.
  2. Additionally, I'd need to know if your hosting is shared or not and possibly what versions of Excel you're looking to support.
  3. It looks like its just an API to parse the files. My guess is it's like using COM to open a sheet and grab content out of a certain cell; note that it requires PHP5. Once you figure out how the API works, I'm sure you could create a driver function that just takes a mapping array and the .xls file to use. This function would open the file and use the mapping array to dump the contents into a MySQL table. I use a similar mechanism for importing dbase files into MySQL.
  4. Given a couple of conditions I'll do this for you by Monday for $1k USD. 1) Provide me with a sample spreadsheet and .sql file to rebuild the relevant tables in your database no later than 4PM Friday. 2) Your host is linux-based (I <i>might</i> be able to pull it off on a windows host) 3) I maintain the right to resell / reuse the code (you can also do the same) (Sorry Barand)
  5. Assuming columns are separated by commas and rows are separated by newlines: <?php $file = file_get_contents($uploaded_file); // you have to point $uploaded_file at the correct file if(!strlen($file)){ // Empty file, do some error handling here } // Newline is different in each major operating system: // Unix - \n // Windows - \r\n // Mac - \r // str_replace below will change newlines to the following: // Unix - \n // Windows - \n\n // Mac - \n // You now have two options: // use str_replace to replace "\n\n" with "\n" // ~OR~ while looping over the rows, discard any that are zero length // NOTE: You might be tempted to use preg_replace to pattern match "\r\n" and "\r" // and replace them with "\n" all in one go, BUT you are going to run into problems with // large files. At least, whenever I use regexps on LARGE files on my system it crashes; // you'll have to get a feel for how big of files you can search with a preg_* function $file = str_replace("\r", "\n", $file); // Convert to rows $rows = explode("\n", $file); foreach($rows as $row){ $row = trim($row); if(!strlen($row)){ continue; // Empty line, skip } $cols = explode(",", $row); // Here we do one of two things if( CALCULATE_NUM_COLUMNS ){ $number_of_columns = count($cols); break; // Get out of the loop, we're only counting number of columns so we only need // the number in the first actual row }else if( PARSE_EACH_ROW ){ // Sanitize each element in $cols for DB entry first!!! // Build SQL statements $sql = "INSERT INTO table (col1, col2, ..., colN) VALUES (" . implode(",", $cols) . ")"; $q = mysql_query($sql); // Perform error checking } } ?>
  6. mjdamato has the right idea, although the choice to store the shipping information really depends on the rest of your database structure. I just wanted to clear up one point of confusion you might be having. You don't need a table with any sort of structure like this: ordered_product_quantities - productID - quantity With that table, you'd store the product ID and how many times it had been ordered. Every time it is ordered, you'd simply update the quantity if it was present in the table or insert a new entry if it wasn't. But like I said, you don't need this table. Using mjdamato's orders_products table, I don't see a productID column (it might be the equivalent of the id column he gave). But let's assume the orders_products table had a productID column. Even though you'd have many entries of orders for that product, you can still get a total of quantities ordered: SELECT product_id, COUNT(qty) AS qtyOrdered FROM orders_products WHERE 1 GROUP BY product_id ORDER BY qtyOrdered
  7. The first thing you need to do is learn how to upload a file. Try and find a tutorial on creating a file upload form and then read this: http://www.php.net/features.file-upload Once the file is uploaded and you've done whatever validation you need to perform, you need to open the file and count the number of fields within the file. Then you can present the user with another form that lists the DB columns and the numbered columns in their table and allows them to match them up. Once that column-matching form is submitted, you can open the file and import the values into the corresponding fields, assuming that all required fields have been matched. The part that is probably hanging you up most is that you're trying to complete a process on the server that requires intermediate user intervention, which means multiple forms and when one is submitted moving the user along to the next form. You can allow the user to do this all in one form if you wish. The form would list the possible table columns and the user would assign an integer value to each one; this integer would correspond to a column in the CSV file. The last element on the form is a file browse field. The post page should open the uploaded file, match the columns up, and insert the data.
  8. No it should not. You have broken your if statement even worse than before. Refer to this: http://www.phpfreaks.com/forums/index.php/topic,110618.msg447497.html#msg447497
  9. SELECT * FROM table WHERE 1 ORDER BY col1, col2, ..., colN
  10. Is there any reason you don't have quotes around admin in if($user_name == admin){ Also, stating: IF 1 THEN ... ELSE IF NOT 1 THEN ... END IF is redundant.
  11. I have to do it without any programming logic, hence the reason I put it in the MySQL forum.
  12. What happens when your Javascript does this when you have non-unique IDs? var el = document.getElementById("nonUniqueID"); (It breaks.)
  13. The only catch would be that each worksheet needs to represent a single tabular layout. If you have a worksheet that does little things like merge cells or display an extra table it might start to get tricky. I'd say that's worth $30k, lol
  14. If each worksheet follows a consistent layout and has the same data in every row, I wonder if you could find a solution just exporting the file to a CSV, or other delimited format, and then using MySQL's LOAD DATA INFILE syntax to read it. http://dev.mysql.com/doc/refman/4.1/en/load-data.html Just thought I'd throw that out there.
  15. You are updating the user's exp in the database and then comparing the user's exp in the object with what's required to level without updating the exp in the object that the user just won. You probably need to add this between the mysql query that updates the DB and the if test: $user->exp += $enemy->level * 4; Also, I just noticed that you have a semi-colon after the closing paren of the if conditional. You copied that from my post, but I copied it from your original (and then just missed the mistake when I made my original reply). That semi-colon is effectively acting as an "empty" if body. The section of code you intended to run as the if body is therefore executing every time, regardless of the if test.
  16. These three lines look like a logic error: mysql_query("UPDATE `users` SET gold = gold + (($enemy->gold/2)*2) WHERE ID = $user->id"); Echo ' <center>You Gain '; echo "$enemy->gold"; echo ' Gold Pieces From The Battle.</center><br><br>'; mysql_query("UPDATE `users` SET gold = gold - (gold/2) WHERE ID = $enemy->ID"); You are setting the winner's gold equal to the enemy's gold and then echo'ing that the winner is receiving gold equal to the amount held by the enemy, which is fine. But then you are decreasing the enemy's gold by half instead of the amount received by the victor; I'm not sure if that's what you intended. Also, in the first line that I pasted you have $user->id while every where else in your code it's $user->ID
  17. I'm looking at your script, but here's a quick note: <?php echo "$user->display_name"; echo ' VS. ';echo "$enemy->display_name<br>"; // Can be written as (slightly more condense than extra echo statements): echo "{$user->display_name} VS. {$enemy->display_name}<br>"; ?>
  18. <?php // Initialize the session. // If you are using session_name("something"), don't forget it now! session_start(); // Unset all of the session variables. $_SESSION = array(); // If it's desired to kill the session, also delete the session cookie. // Note: This will destroy the session, and not just the session data! if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } // Finally, destroy the session. session_destroy(); ?> Straight out of the manual for session_destroy. It shows how to clear the session data variables and the cookie as well, which was the rub for you. You learned wrong. Example: "Water can be cold but it can also be hot." If it were annoying I wouldn't have responded; if it were simplistic I wouldn't have show you how I found the answer when I originally had this question myself. Learning how to program is more than learning a language, it's learning how to become more resourceful. You can always find the answers to the simplistic questions because they've been asked dozens of times before; but you need to develop the skills to uncover the answers to questions that cause hair loss. I post questions occasionally, however most of them fall into more advanced topics; as such, by the time someone answers I've usually found a solution or work-around I can apply to my situation, but not always. The only reason I responded the way I did is because it seemed to me that if you had dug around for the extra amount of time that you spent writing the post, you would have probably found the solution. Even typing session_destroy into the search function for this site brings up several results that might have lead you to a resolution. I will, thanks!
  19. Do you really think anyone is going to type a response that is 2^32 characters in length on a forum? Do you realize how big that is? Let's assume that your keyboard has a key repeat rate of 50 chars per second. That means if I just held down the 'a' key, it'd produce 50 of them per second. Let's figure out how long that'd take to produce 2^32 of the letter 'a'. 2^32 chars / (50 char / s) = 85899345.92s 85899345.92s / 60 / 60 / 24 = 994 days Let's not even worry about the logistics of the user's machine crashing from not having enough memory to hold that many chars in memory at once. Or uploading 2^32 bytes worth of data to the server. You can probably safely create the column of type TEXT, or 2^16 and never have a problem. As for the database engine setting aside large chunks of space for small posts, I wouldn't worry about it. The people who develop and maintain MySQL are more clever than you're giving them credit.
  20. Post the whole file if you can. You have an error somewhere and I'm guessing its bad logic / syntax.
  21. I have to wonder why you included that first if test: if ( $user->exp = $expfornextlevel;) { mysql_query("UPDATE `users` SET level = level+(1) WHERE ID = $user->ID"); mysql_query("UPDATE `users` SET exp = 0 WHERE ID = $user->ID"); } if ($user->exp > $expfornextlevel); { $difference = ($user->exp - $expfornextlevel); // Why do you have parens here? mysql_query("UPDATE `users` SET level = level+(1) WHERE ID = $user->ID"); mysql_query("UPDATE `users` SET exp = $difference WHERE ID = $user->ID"); } Why not: if ($user->exp >= $expfornextlevel); // NOTICE DIFFERENCE IN COMPARISON { $difference = $user->exp - $expfornextlevel; mysql_query("UPDATE `users` SET level = level+(1) WHERE ID = $user->ID"); mysql_query("UPDATE `users` SET exp = $difference WHERE ID = $user->ID"); } None of what you originally pasted deals with any of this; you probably have an error elsewhere in your program.
×
×
  • 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.