scootstah
Staff Alumni-
Posts
3,858 -
Joined
-
Last visited
-
Days Won
29
Everything posted by scootstah
-
How to prevent txt files from getting cached?
scootstah replied to Krystal's topic in PHP Coding Help
A quick hack is to append a timestamp to the URL. So instead of http://example.com/logs.txt, you have http://example.com/logs.txt?123456789 -
File download appearing as data within page - not downloading
scootstah replied to Jimity's topic in PHP Coding Help
So if you put this at the very top of your code, you don't get errors? ini_set('display_errors', 'On'); error_reporting(-1);Are you using output buffering? -
Reverse words in a sentence without using PHP functions
scootstah replied to Dota2's topic in PHP Coding Help
Damn, way to show me up req. -
Reverse words in a sentence without using PHP functions
scootstah replied to Dota2's topic in PHP Coding Help
That was kind of fun. Here's my take: <?php function reverseString($input) { $currentWord = ''; $words = array(); for ($i = 0; $i < strlen($input); $i++) { if ($input[$i] == ' ') { $words[] = $currentWord; $currentWord = ''; continue; } $currentWord .= $input[$i]; if ($i == (strlen($input) - 1)) { $words[] = $currentWord; } } if (!empty($words)) { $reversed = array(); for ($i = (count($words) - 1); $i >= 0; $i--) { $reversed[] = $words[$i]; } $output = ''; foreach ($reversed as $word) { $output .= $word . ' '; } return trim($output); } } $input = 'this is phpfreaks'; $output = reverseString($input); echo "Input: $input<br />Output: $output"; Input: this is phpfreaks Output: phpfreaks is this -
File download appearing as data within page - not downloading
scootstah replied to Jimity's topic in PHP Coding Help
You're probably sending output before the headers causing them to not send. And you probably don't have error reporting turned on or you would see that. -
mysqli_real_escape_string alternative for decimal ?
scootstah replied to bambinou1980's topic in PHP Coding Help
Not a problem man. As long as you do your due diligence and don't expect spoon feeding, we will be happy to help you along the way. -
mysqli_real_escape_string alternative for decimal ?
scootstah replied to bambinou1980's topic in PHP Coding Help
Because then you don't have to manage anything. You only have two statuses now, but you could have many more later on. -
mysqli_real_escape_string alternative for decimal ?
scootstah replied to bambinou1980's topic in PHP Coding Help
SELECT orders.*, order_status.status FROM orders JOIN order_status ON order_status.id = orders.order_status_idYou should be using auto increment on ID's though. And since you have a value of 0, that tells me that you are not doing that. -
Fatal error: Call to a member function query() on a non-object
scootstah replied to vet911's topic in Applications
Look at the top. Your database connection is failing with the credentials that you have used. -
It's just a way to re-use code in the way that you are trying to do. It is a pretty typical jQuery solution: apply some class to every element that you want to have some functionality, and then bind to that one class and boom, everything gets it. And yes, $(this) will still reference the actual element that was clicked, so you could still differentiate between someone clicking color-side-a and color-side-b, if you wanted to.
-
That's what I figured. Since you didn't create an instance of Cust, you cannot use $this. $this references the instance of the class in which it is called. Also, you shouldn't be calling methods statically unless they are explicitly labeled as static.
-
Yes, pretty much any real-time chat system is going to use TCP sockets. With a TCP connection, a client connects to a server and the connection remains open, or, "persistent". Data is more-or-less only sent one way or the other when something happens, like when a chat message is sent. If you do not use a persistent connection, and instead rely on polling, then you have to request data at continuous intervals even if there is no data to give. In such a system the messages will not be in real time, either, and will only be received when the client asks for them. Now, if there is not going to be a web component then there is no point using WebSockets. You're better off just using straight up TCP protocol if you don't need web chat. And I wouldn't use PHP either, it's not really good at that. Java or NodeJS would be better choices.
-
How are you calling update()?
-
I don't understand the problem. If the user is active, then the session will get refreshed every time they view a page, no? Is that not what you want to happen?
-
That is just a testament to how easy PHP is to pick up and build something with. I would argue over the term "professional software". Just because software is popular doesn't mean that it was built by professionals. There are many, many, many horribly written PHP apps that are super popular today. Most of the forum software, most of the ecommerce software, most of the blogging software, etc. I wouldn't call any of that professional software.
-
You could... 1. Create a common class that you are binding to, instead of .color-side-a and .color-side-b. Like, <div class="color-side color-side-a"> ... </div> <div class="color-side color-side-b"> ... </div> $('.color-side .number-of-color-field > div').on('click', function(){ ... }); 2.Use multiple selectors on the same event. $('.color-side-a, .color-side-b').on('click', '.number-of-color-field > div', function(){ ... }); 3.Make a function that you can call from both events. function pickColor(selector, colorAttr) { var colorHolder = selector.attr('class'); $('.colorSelectBox').css({"left": "100px", "top": "570px"}).toggle(); $('div.black').add('div.yellow').on('click', function(){ var splitClass = colorHolder.split(" "); selector.closest('div').find('.'+splitClass[0] + '.'+splitClass[1]).css({"background": colorAttr}).attr('value', colorAttr); }); } $('.color-side-a .number-of-color-field > div').on('click', function(){ pickColor($('.color-side-a'), $(this).attr('value')); }); $('.color-side-b .number-of-color-field > div').on('click', function(){ pickColor($('.color-side-b'), $(this).attr('value')); }); Unless there is some context that I don't know of, #1 is the best choice in my opinion.
-
Easy is a relative term. PHP is pretty straightforward, it has great documentation, and it has a massive community. It has tons of existing libraries and frameworks. To me, these qualities make it easy. But if PHP is your first take on programming, then you might not think it is easy. But you're really talking about programming and not PHP specifically. You see, once you have learned the concepts of programming and understand them well, you can apply that knowledge to any programming language. Every programming language is still programming, and they all follow the same principals. To a seasoned developer, PHP is easy. To a beginner, PHP is hard.
-
If you have a Javascript error before the jQuery library, then all script execution will end. Thus, jQuery will never have been defined.
-
No. It sounds like you need a one-to-many relation here. The schema was designed for only one city, but now it should be re-designed to support multiple cities. Don't copy data. Once you have a new table for the event cities, you just need to insert the event, get the last insert ID, and then insert each city into its own table along with the event ID. Then when you select the event, you can JOIN the cities.
-
Help with Warning: Invalid argument supplied for foreach()
scootstah replied to bambinou1980's topic in PHP Coding Help
It doesn't work because $_POST['product_name'] is a string and not an array. -
Just because you found it online doesn't mean that it is good. That code is very old and outdated as well. You're not creating a separate class for database connection. PHP comes with the mysqli class already, you don't have to create that.
-
Sure. Duplicate code is bad code, even in tests. Re-use whenever possible. You can make it a trait, or some abstract class that you extend, or instantiate it in your test, or whatever you want to do.
-
It means that $pdo is not an object in the scope that you're trying to use it. Do not use globals. Instantiate the PDO object and then pass it via a constructor argument to each class that needs it. class LoginRegistration { private $pdo; public function __construct(PDO $pdo) { $this->pdo = $pdo; } } ................. try{ $pdo = new PDO('mysql:host=localhost;dbname=oopreg', 'root', ''); } catch (PDOException $e){ exit('Database error'); } $loginRegistration = new LoginRegistration($pdo);