Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/28/2023 in all areas

  1. Given you're trying to compare with LIKE, I'm guessing that means the each row has a list of zipcodes in that column, not a single zipcode? Given the column name is dynamic, I'm guessing you have different columns for each state too (ie, FLZips, GAZips, etc). If that's the case, then that is not the proper way to design your database. A column should only contain a single value (ie, a single zipcode) per row, and you shouldn't have multiple columns for essentially the same info. You should have a second table that associates the zipcodes and the state with a business, with a single row per zipcode and state combo. For example: create table business_zipcodes ( businessId int not null, Zipcode varchar(10) not null, State varchar(2) not null ); You'd then join to that table in your select to search for a particular zip code. SELECT * FROM DATA INNER JOIN business_zipcodes on business_zipcodes.businessId=DATA.id WHERE DATA.id=? and business_zipcodes.State='FL' and business_zipcodes.zipcode=? Notice I replaced your variables with ? also. Sticking variables into your query is also another thing you should not be doing (read up on SQL Injection attacks), you should be using a prepared statement with bound parameters. Your code would end up looking more like this: $stmt = mysqli_prepare($con, " SELECT * FROM DATA INNER JOIN business_zipcodes on business_zipcodes.businessId=DATA.id WHERE DATA.id=? and business_zipcodes.State='FL' and business_zipcodes.Zipcode=? "); mysqli_stmt_bind_param($stmt, 'is', $_GET['id'], $_GET['Business_Zip']); mysqli_stmt_execute($stmt); while ($row = mysqli_stmt_fetch($stmt)){ echo '<br><img src="images/Florida.png" style="padding-bottom:8px;">'; }
    1 point
  2. Nor could any client just call your function, so why bother with your private hack in the first place? Private vs public functions has nothing to do with the client/browser, but with other parts of your code. A private function can only be called by some other function within the same class, not by code outside that class. Public function can be called by any part of your code. It may seem pointless when your just developing some small-time blog made out of one page and a couple includes but when you get into real programming work it becomes important. I feel like you are either trolling or just feel like your smarter than everyone else. Seems obvious at least that you have no interest in actually learning programming techniques. By all means, keep that hot garbage you call code for yourself, nobody wants it.
    1 point
  3. Maybe because whatever you're doing doesn't need OOP. Maybe you just don't understand OOP well enough to see the usefulness. It's hard to say. The example class you posted here seems pretty pointless. If you want to see your class fixed up though, <?php declare (strict_types=1); namespace SpyderEyes; class Reflection { protected string $mirror; public function __construct(string $shine){ $this->mirror = $shine; } public function shine() : string{ return $this->mirror; } public function dust() : string{ return bin2hex(base64_encode($this->mirror)); } } try { $reflector = new Reflection(['Mirror, Mirror on the Wall']); echo '<p>' . $reflector->shine() . '</p>' . PHP_EOL; echo '<p>' . $reflector->dust() . '</p>' . PHP_EOL; } catch (\TypeError $error){ echo 'Oops'; } The constructor will throw a type error if you pass a non-string value which you can catch and handle if you want. Since the constructor can only accept a string, you ensure that the mirror property will always be a string and thus do not have to do any checking in the individual methods. One way to dive into the deep end and see how OOP can be beneficial is by looking at the various frameworks that exist. I like Symfony personally and think spending some time using and learning about it can be quite beneficial in showing how useful an OOP approach can be. A couple other reasons why classes are nice: Class autoloading saves you from getting into an include/require nightmare. IDE's can easily parse the classes and provide auto-completion. Yes, return is valid in a function. Returning a value from a constructor is not though. Take your original code that returned false class Reflection { protected string $mirror; public function __construct($shine){ if (!is_string($shine)){ return false; } $this->mirror = $shine; } } What do you expect return false to do there? If you think it's something you can test for to see if the constructor failed, you're mistaken $o = new Reflection([]); if ($o === false){ echo 'Oops'; } else { echo 'Success!'; } That if statement will never be true, $o will always be an instance of Reflection. The return only causes the constructor to stop running, which means your mirror property never gets initialized and thus causes you future issues. This I don't understand at all. Trying to emulate private functions by checking if some session variable exists make zero sense and doesn't actually make the function private at all since all one would have to do to use it is set that variable.
    1 point
  4. What you're trying to do doesn't make any sense at all. Perhaps you'll have a better time learning OOP if you aim your efforts in a more sane direction?
    1 point
This leaderboard is set to New York/GMT-05:00
×
×
  • 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.