ManiacDan
Staff Alumni-
Posts
2,604 -
Joined
-
Last visited
-
Days Won
10
Everything posted by ManiacDan
-
Javascript supports json encoding, but like mj said it doesn't support named keys. Your "team name" and "team nationality" will turn into 0 and 1, respectively. -Dan
-
Remvoing an object from $_SESSION
ManiacDan replied to Freedom-n-Democrazy's topic in PHP Coding Help
Buddski's solution is similar to my original one except that it doesn't use the product ID as the key (which makes the loop necessary). Also note that nobody, not even you, has used objects. Nobody does the "one line for every product" thing, not even companies that take orders over the phone. Look at the receipt next time you go to a diner. The waitress doesn't write: Coffee Coffee Coffee She writes: Coffee x 3 Use the quantity, people don't want to see six copies of the same thing in their cart. What if they want to remove them? You make them click 6 times. What if they wanted 12 instead? They have to go back and click "add to cart" instead of editing the "quantity" box in the cart. Keeping the quantity on the row is the proper solution. -Dan -
The correct way to do it is by sorting the query. If you can't sort the query for some reason, then array_multisort or usort are the functions you need. -Dan
-
Remvoing an object from $_SESSION
ManiacDan replied to Freedom-n-Democrazy's topic in PHP Coding Help
You'll have to loop through the array to find the matches. The proper way to do a shopping cart is to store the item ID as the key, and put the QUANTITY on the object, so if someone buys an item you just do: $itemTheyWant = 123; $quantityTheyWant = 3; if ( isset($_SESSION['cart'][$itemTheyWant]) ) { $_SESSION['cart'][$itemTheyWant]['quantity'] += $quantityTheyWant; } else { $_SESSION['cart'][$itemTheyWant] = array('itemId' => $itemTheyWant, 'quantity' => $quantityTheyWant); } Modified to fit your structure of course, I know you're using objects. -Dan -
Also, there's absolutely no reason to have a form here.
-
For the love of god, copy and paste. Every time you show a new example you've subtly altered the code I've given you. Why does your code not match the code I gave you? the code I gave you worked. Replacing your JS function with the actual line I gave you works in chrome: <script type="text/javascript" language="javascript"> function dump() { document.getElementById('debug').innerHTML = document.documentElement.innerHTML; } </script> <form action="#" name="form1"> <fieldset><legend>form</legend> <textarea rows="10" cols="20" name="textarea1" id="debug"> </textarea> <button type="button" onclick="dump()">Get CODE</button> </fieldset> -Dan
-
The first one is wrong because the JS is inside the textarea when it should be outside. The second is wrong because you used value instead of innerHTML and you're not calling this function anywhere.
-
This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=345289.0
-
Your first step would simply be to learn PHP. Basic form processing and upload control is one of the best ways to learn. You'll want to store these files on the filesystem but use a database to store their locations. That way, you get the reliability and speed of storing files on the filesystem but the ability to search and update like a database. Also note that you might get a letter from some lawyers. Movie scripts are copyrighted and protected works. I am not a lawyer, but this sounds like a bad idea. -Dan
-
So you have a whole bunch of files on your filesystem but you don't know who uploaded what? unless you specifically logged this information you cannot get it back. You can start from right now and start recording, but there's no way to add up a random number of files based on which web user created them. -Dan
-
intval does work. If you give it "potato123" intval says "that's not a number, so let's say zero." What happens if your string is "ab12cd34." Do you want the number 1,234 or do you want two numbers?
-
I didn't look at the code (mostly because I trust reqinix) but I found this odd: It's possible that it's illegal for you to sell this script and the authors are striking back at you. Possible, but not very likely. Given what requinix said, they don't have the skills to attack you, but it's still a thought. Was the script "free" in that it came with absolutely no copyright or licensing restrictions?
-
Never use queries in a loop, always use a JOIN. SELECT table_b.listing_id, listing_name, start_date, end_date FROM Table_a join table_b on table_a.listing_id = table_b.listing_id WHERE (start_date BETWEEN '2011-08-01 00:00:00' AND '2011-08-31 00:00:00') AND (end_date BETWEEN '2011-08-01 00:00:00' AND '2011-08-31 00:00:00') -Dan
-
Leave off the WHERE clause entirely if you want to match all rows.
-
SELECT * FROM report WHERE (start_date BETWEEN '2011-08-01 00:00:00' AND '2011-08-31 00:00:00') AND (end_date BETWEEN '2011-08-01 00:00:00' AND '2011-08-31 00:00:00') -Dan
-
Minor note: You should be doing this with mod_rewrite, not htaccess.
-
When they upload something, record how big it was.
-
Again, stop confusing PHP with HTML. PHP is a language that generates (for the most part) text output. PHP can be used to generate novels, emails, invoices, OR html documents. PHP doesn't care what it's generating and whatever is generated doesn't care that PHP was involved. You are not at all interested in the PHP side of this equation. At all. Really, you're not. This is entirely an html/javascript question. document.getElementById('idOfYourTextAreaHere').innerHTML = document.documentElement.innerHTML; That's all you have to do. Run that javascript at the bottom of the page (or put it into a button) and as long as you have a textarea on the page with the proper ID then it will be filled with the page's entire content (minus the <html> and </html> tags and any doctype declarations). I don't know why you need this rather than the "view source" that everyone else uses, but there's the solution. -Dan
-
PHP, HTML, and javaScript are entirely separate languages. Don't get them confused. It doesn't matter which language generated the page if all you care about is the HTML source. That being said, if someone wants to view the HTML source of your page, they have to press ctrl+U. That's all. Do it right now. If you really want it to show up in a textbox, I'm sure that you can use some variant of the innerHTML attribute on the entire document, then stick that into a textarea. I wouldn't recommend that though, it might screw up some browsers. The "view source" menu option built into all browsers is enough. -Dan
-
You can simulate this with divs and javascript, but I don't believe it's possible in normal HTML.
-
The follow items are separate languages and technologies that have nothing to do with each other at the fundamental level: PHP MySQL Regular Expressions HTML/CSS JavaScript/AJAX/Jquery Those items above, when combined properly by a person skilled in all 5 of them, create a fully functioning website. They are NOT the same language, and an expert in one of them is not necessarily an expert in another. Most of the moderators of the PHP boards are experts in all 5 simply through virtue of experience (and being awesome). What most new developers fail to understand is that PHP doesn't "know" anything about your HTML form or your MySQL database. PHP "knows" only PHP things. You must tell it, specifically and explicitly, if you want it to fetch information from a database, or receive information from an HTML form. If you want to make a web page you need to know HTML. If you want to make a DYNAMIC web page you need to know some server-side language such as PHP. You need both. -Dan
-
Always do everything from the document root, it's far more streamlined than attempting to figure out how deep you are dynamically.
-
What have you tried? You did exactly what I said and it still doesn't work? What's the new error message?
-
Well...like it says in the error message, allow_url_fopen is disabled in your configuration. You need to enable it. Go find php.ini, open it, find allow_url_fopen, and change it from a 0 to a 1. Then restart your server. If you're on a shared host, you can attempt to reset it manually, or use file_get_contents or curl to pull down the file you want, then load it into SimpleXML using another function. -Dan
-
You can execute the page, capture the result, and fill the DIV with the HTML of the result. You could also use an iframe and simply use JS to reset the src attribute. -Dan