Jump to content

Search the Community

Showing results for tags 'class'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. Hi i m getting problem in uploading files to my site i am not expert in java i m novice whenever i trying to upload files via jupload it give me error ClassNotFoundException wjhk.jupload2JUploadApplet some days back it was working fine and its w-script which use jupload to upload bulk wallpapers i dont know how to deal with this problem please help me
  2. Hi guys, It's a simple question really (just getting used to php - actionscript 3.0 developer!) but I need to know how I can pass a CSS class into the arguments in a PHP function, then have it apply that style to text in html. What I have so far is: <?php function addText($text,$class) { ?> <div class= $class > <p><?php echo $text ?></p> </div> <?php } ?> But it doesn't work, the <div class = $class > should be different I think. Anybody got a solution?
  3. I have a class for building forms and I want to upgrade it to handle Bootstrap. I'd like to use my current methods to build the Bootstrap elements, but I don't want all of this new Bootstrap code cluttering up my current Forms class, so I'd like to put it into its own class in a separate file. Below is a very simple example of what I'm trying to do. Obviously this doesn't work and the code is wrong, however, from this you can hopefully see what I'm trying to accomplish. <?php class Forms { public function input_text($name) { return '<input type="text" name="'.$name.'">'; } } class Bootstrap { public function bootstrap_input_text($name) { $return = '<div class="control-group">'; $return .= '<label class="control-label" for="'.$name.'">First name</label>'; $return .= '<div class="controls">'; $return .= $this->Forms->input_text($name); $return .= '</div>'; $return .= '</div>'; return $return; } } $form = new Forms(); echo $form->bootstrap_input_text('fname');
  4. Hello, I am brand new to this forum so I am not sure if I am posting in the right place but I will give it a shot: I have been making PHP Classes for a while and thinking about giving away/selling them. I currently have a Flat file database Class that allows you to turn a text file into a table within a database. The queries are easy for example: select('FROM users WHERE username=hello');. This Flatfile Database contains many of the same functions as mysql. I decided to make this as i see mysql is being discontinued in the next version of PHP. Another class i have created is a login class. Setup is easy of course, all you have to do it simply include the main file(all in a folder called Login) and then wherever you want it simple past this code: new gLogin();. TADA you have a login. Please post any questions, concerns, or requests for new classes. Thank you, gamble
  5. I really cannot understand it, I've tried several different ways of writing it that I'm sure I've used before, and I simply cannot get :hover to work with any of my divs... html: <a href=''><div id='menu' class='button1'></div></a> <a href=''><div id='menu' class='button2'></div></a> <a href=''><div id='menu' class='button3'></div></a> <a href=''><div id='menu' class='button4'></div></a> css: #menu { width:75px; height:75px; background-color:red; /* background-image:url('menu.jpg'); */ float:left; margin:20px; } .button1:hover { /* background-position:75px 75px; */ background-color:yellow; } as you can see I've commented out the image, ultimately I want the image to appear, but for now I can't get the :hover to change the state of the div at all, no reaction... any help would be much appreciated, its really frustrating me...
  6. I'm fairly new to object orientated PHP and I was trying to think of a better way to connect to a MySQLi database within classes and functions, instead of just putting down an include everywhere. So far I came up with this: database.php <?php class database { protected $db_name = 'database'; protected $db_user = 'root'; protected $db_password = 'password'; protected $db_host = 'localhost'; function __construct(){ $this->connect(); } public function connect(){ $this->db = new mysqli($this->db_host, $this->db_user, $this->db_password, $this->db_name); } } $db = new database; ?> test.php class test{ private function getDb(){ include("database.php"); return $db; } public function test1(){ $find = $this->getDb()->db->query("SELECT * FROM user"); $rows = $find->num_rows; return $rows; } } and then just putting echo $test->test1(); on my page. I did have other functions inside the database class, but I've since scrapped those, so it just looks like that atm. It does work... however, I'm not sure how good or bad it is. In particular the first line in the test1() function. I have a feeling its a terrible way to do it... Or is it fine? like efficiency wise etc? before I would just use an include within every function. so I'd just do: $db->query(" "); Eventually I will have a few classes like user, etc, and these would all need to manipulate the database. So I was just thinking of plopping the getDb() function at the top of each of them and just include the database stuff... I tried looking at how phpBB and wordpress handle databases, but theirs are just full of unnecessary stuff for me and its just difficult to decipher. They use a global I think?
  7. Long ago I started with a php function that generated an html select list from a mysql table. Over time, I've needed versions that did various things differently (two fields displayed between the <option> and </option> or a div displayed based on the selected value) so I've kept building new versions. Every time I build a new version I think "boy I should make a class and extend it to do things the new way" but I never have and now I must have half a dozen versions of the code. Today I sat down and started coding my class and quickly realized that I need to actually figure out what I put in the parent class and where I draw the line and create another class based on the first. Mostly I code procedural and I could really use some help thinking this through. Here's what I have in terms of permutations that I want to accomplish: Build an SQL select set a where clause set an order by select multiple columns to concatenate as labels (for example: <option citycode='$cid'>$city, $state, $country</option> ) Build html Allow list to start with value ='' (eg <option value=''>Choose a state</option> <option value='AK'>Alaska...) set a selected= value (or values for multiples) <div> s No <div> display Display of a <div> if other is selected input type=text textarea Display of a <div> for each value seected Types Select list single or multiple Radio checkboxes So, do I create a class with methods for each type of html list and a child class for the divs? A parent with the divs and children where I override the method that created the html for radio and checkboxes, something else entirely? Thanks, David
  8. Hi everybody, I am currently working with the php_serial.class to send out signals through the serial port of my computer. I set up a webserver on Windows with Apache and its working fine. The only problem is, that when I press the button on the homepage, it takes like 6 seconds to actually send something out the port. You guys have any ideas why this could be happening? I tested under Windows 7 and XP with the newest version of Apache Server and several different computers with different hardware. Always the same results. Here is the class: <?php define ("SERIAL_DEVICE_NOTSET", 0); define ("SERIAL_DEVICE_SET", 1); define ("SERIAL_DEVICE_OPENED", 2); /** * Serial port control class * * THIS PROGRAM COMES WITH ABSOLUTELY NO WARANTIES ! * USE IT AT YOUR OWN RISKS ! * * @author Rémy Sanchez <thenux@gmail.com> * @thanks Aurélien Derouineau for finding how to open serial ports with windows * @thanks Alec Avedisyan for help and testing with reading * @copyright under GPL 2 licence */ class phpSerial { var $_device = null; var $_windevice = null; var $_dHandle = null; var $_dState = SERIAL_DEVICE_NOTSET; var $_buffer = ""; var $_os = ""; /** * This var says if buffer should be flushed by sendMessage (true) or manualy (false) * * @var bool */ var $autoflush = true; /** * Constructor. Perform some checks about the OS and setserial * * @return phpSerial */ function phpSerial () { setlocale(LC_ALL, "en_US"); $sysname = php_uname(); if (substr($sysname, 0, 5) === "Linux") { $this->_os = "linux"; if($this->_exec("stty --version") === 0) { register_shutdown_function(array($this, "deviceClose")); } else { trigger_error("No stty availible, unable to run.", E_USER_ERROR); } } elseif(substr($sysname, 0, 7) === "Windows") { $this->_os = "windows"; register_shutdown_function(array($this, "deviceClose")); } else { trigger_error("Host OS is neither linux nor windows, unable tu run.", E_USER_ERROR); exit(); } } // // OPEN/CLOSE DEVICE SECTION -- {START} // /** * Device set function : used to set the device name/address. * -> linux : use the device address, like /dev/ttyS0 * -> windows : use the COMxx device name, like COM1 (can also be used * with linux) * * @param string $device the name of the device to be used * @return bool */ function deviceSet ($device) { if ($this->_dState !== SERIAL_DEVICE_OPENED) { if ($this->_os === "linux") { if (preg_match("@^COM(\d+):?$@i", $device, $matches)) { $device = "/dev/ttyS" . ($matches[1] - 1); } if ($this->_exec("stty -F " . $device) === 0) { $this->_device = $device; $this->_dState = SERIAL_DEVICE_SET; return true; } } elseif ($this->_os === "windows") { if (preg_match("@^COM(\d+):?$@i", $device, $matches) and $this->_exec(exec("mode " . $device)) === 0) { $this->_windevice = "COM" . $matches[1]; $this->_device = "\\.\com" . $matches[1]; $this->_dState = SERIAL_DEVICE_SET; return true; } } trigger_error("Specified serial port is not valid", E_USER_WARNING); return false; } else { trigger_error("You must close your device before to set an other one", E_USER_WARNING); return false; } } /** * Opens the device for reading and/or writing. * * @param string $mode Opening mode : same parameter as fopen() * @return bool */ function deviceOpen ($mode = "r+b") { if ($this->_dState === SERIAL_DEVICE_OPENED) { trigger_error("The device is already opened", E_USER_NOTICE); return true; } if ($this->_dState === SERIAL_DEVICE_NOTSET) { trigger_error("The device must be set before to be open", E_USER_WARNING); return false; } if (!preg_match("@^[raw]\+?b?$@", $mode)) { trigger_error("Invalid opening mode : ".$mode.". Use fopen() modes.", E_USER_WARNING); return false; } $this->_dHandle = @fopen($this->_device, $mode); if ($this->_dHandle !== false) { stream_set_blocking($this->_dHandle, 0); $this->_dState = SERIAL_DEVICE_OPENED; return true; } $this->_dHandle = null; trigger_error("Unable to open the device", E_USER_WARNING); return false; } /** * Closes the device * * @return bool */ function deviceClose () { if ($this->_dState !== SERIAL_DEVICE_OPENED) { return true; } if (fclose($this->_dHandle)) { $this->_dHandle = null; $this->_dState = SERIAL_DEVICE_SET; return true; } trigger_error("Unable to close the device", E_USER_ERROR); return false; } // // OPEN/CLOSE DEVICE SECTION -- {STOP} // // // CONFIGURE SECTION -- {START} // /** * Configure the Baud Rate * Possible rates : 110, 150, 300, 600, 1200, 2400, 4800, 9600, 38400, * 57600 and 115200. * * @param int $rate the rate to set the port in * @return bool */ function confBaudRate ($rate) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set the baud rate : the device is either not set or opened", E_USER_WARNING); return false; } $validBauds = array ( 110 => 11, 150 => 15, 300 => 30, 600 => 60, 1200 => 12, 2400 => 24, 4800 => 48, 9600 => 96, 19200 => 19, 38400 => 38400, 57600 => 57600, 115200 => 115200 ); if (isset($validBauds[$rate])) { if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " " . (int) $rate, $out); } elseif ($this->_os === "windows") { $ret = $this->_exec("mode " . $this->_windevice . " BAUD=" . $validBauds[$rate], $out); } else return false; if ($ret !== 0) { trigger_error ("Unable to set baud rate: " . $out[1], E_USER_WARNING); return false; } } } /** * Configure parity. * Modes : odd, even, none * * @param string $parity one of the modes * @return bool */ function confParity ($parity) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set parity : the device is either not set or opened", E_USER_WARNING); return false; } $args = array( "none" => "-parenb", "odd" => "parenb parodd", "even" => "parenb -parodd", ); if (!isset($args[$parity])) { trigger_error("Parity mode not supported", E_USER_WARNING); return false; } if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " " . $args[$parity], $out); } else { $ret = $this->_exec("mode " . $this->_windevice . " PARITY=" . $parity{0}, $out); } if ($ret === 0) { return true; } trigger_error("Unable to set parity : " . $out[1], E_USER_WARNING); return false; } /** * Sets the length of a character. * * @param int $int length of a character (5 <= length <= * @return bool */ function confCharacterLength ($int) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set length of a character : the device is either not set or opened", E_USER_WARNING); return false; } $int = (int) $int; if ($int < 5) $int = 5; elseif ($int > $int = 8; if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " cs" . $int, $out); } else { $ret = $this->_exec("mode " . $this->_windevice . " DATA=" . $int, $out); } if ($ret === 0) { return true; } trigger_error("Unable to set character length : " .$out[1], E_USER_WARNING); return false; } /** * Sets the length of stop bits. * * @param float $length the length of a stop bit. It must be either 1, * 1.5 or 2. 1.5 is not supported under linux and on some computers. * @return bool */ function confStopBits ($length) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set the length of a stop bit : the device is either not set or opened", E_USER_WARNING); return false; } if ($length != 1 and $length != 2 and $length != 1.5 and !($length == 1.5 and $this->_os === "linux")) { trigger_error("Specified stop bit length is invalid", E_USER_WARNING); return false; } if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " " . (($length == 1) ? "-" : "") . "cstopb", $out); } else { $ret = $this->_exec("mode " . $this->_windevice . " STOP=" . $length, $out); } if ($ret === 0) { return true; } trigger_error("Unable to set stop bit length : " . $out[1], E_USER_WARNING); return false; } /** * Configures the flow control * * @param string $mode Set the flow control mode. Availible modes : * -> "none" : no flow control * -> "rts/cts" : use RTS/CTS handshaking * -> "xon/xoff" : use XON/XOFF protocol * @return bool */ function confFlowControl ($mode) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set flow control mode : the device is either not set or opened", E_USER_WARNING); return false; } $linuxModes = array( "none" => "clocal -crtscts -ixon -ixoff", "rts/cts" => "-clocal crtscts -ixon -ixoff", "xon/xoff" => "-clocal -crtscts ixon ixoff" ); $windowsModes = array( "none" => "xon=off octs=off rts=on", "rts/cts" => "xon=off octs=on rts=hs", "xon/xoff" => "xon=on octs=off rts=on", ); if ($mode !== "none" and $mode !== "rts/cts" and $mode !== "xon/xoff") { trigger_error("Invalid flow control mode specified", E_USER_ERROR); return false; } if ($this->_os === "linux") $ret = $this->_exec("stty -F " . $this->_device . " " . $linuxModes[$mode], $out); else $ret = $this->_exec("mode " . $this->_windevice . " " . $windowsModes[$mode], $out); if ($ret === 0) return true; else { trigger_error("Unable to set flow control : " . $out[1], E_USER_ERROR); return false; } } /** * Sets a setserial parameter (cf man setserial) * NO MORE USEFUL ! * -> No longer supported * -> Only use it if you need it * * @param string $param parameter name * @param string $arg parameter value * @return bool */ function setSetserialFlag ($param, $arg = "") { if (!$this->_ckOpened()) return false; $return = exec ("setserial " . $this->_device . " " . $param . " " . $arg . " 2>&1"); if ($return{0} === "I") { trigger_error("setserial: Invalid flag", E_USER_WARNING); return false; } elseif ($return{0} === "/") { trigger_error("setserial: Error with device file", E_USER_WARNING); return false; } else { return true; } } // // CONFIGURE SECTION -- {STOP} // // // I/O SECTION -- {START} // /** * Sends a string to the device * * @param string $str string to be sent to the device * @param float $waitForReply time to wait for the reply (in seconds) */ function sendMessage ($str, $waitForReply = 0.1) { $this->_buffer .= $str; if ($this->autoflush === true) $this->flush(); usleep((int) ($waitForReply * 1000000)); } /** * Reads the port until no new datas are availible, then return the content. * * @pararm int $count number of characters to be read (will stop before * if less characters are in the buffer) * @return string */ function readPort ($count = 0) { if ($this->_dState !== SERIAL_DEVICE_OPENED) { trigger_error("Device must be opened to read it", E_USER_WARNING); return false; } if ($this->_os === "linux") { $content = ""; $i = 0; if ($count !== 0) { do { if ($i > $count) $content .= fread($this->_dHandle, ($count - $i)); else $content .= fread($this->_dHandle, 128); } while (($i += 128) === strlen($content)); } else { do { $content .= fread($this->_dHandle, 128); } while (($i += 128) === strlen($content)); } return $content; } elseif ($this->_os === "windows") { /* Do nohting : not implented yet */ } trigger_error("Reading serial port is not implemented for Windows", E_USER_WARNING); return false; } /** * Flushes the output buffer * * @return bool */ function flush () { if (!$this->_ckOpened()) return false; if (fwrite($this->_dHandle, $this->_buffer) !== false) { $this->_buffer = ""; return true; } else { $this->_buffer = ""; trigger_error("Error while sending message", E_USER_WARNING); return false; } } // // I/O SECTION -- {STOP} // // // INTERNAL TOOLKIT -- {START} // function _ckOpened() { if ($this->_dState !== SERIAL_DEVICE_OPENED) { trigger_error("Device must be opened", E_USER_WARNING); return false; } return true; } function _ckClosed() { if ($this->_dState !== SERIAL_DEVICE_CLOSED) { trigger_error("Device must be closed", E_USER_WARNING); return false; } return true; } function _exec($cmd, &$out = null) { $desc = array( 1 => array("pipe", "w"), 2 => array("pipe", "w") ); $proc = proc_open($cmd, $desc, $pipes); $ret = stream_get_contents($pipes[1]); $err = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); $retVal = proc_close($proc); if (func_num_args() == 2) $out = array($ret, $err); return $retVal; } // // INTERNAL TOOLKIT -- {STOP} // } ?> And this is the index file of the website <?php //check the GET action var to see if an action is to be performed if (isset($_GET['action'])) { //Action required //Load the serial port class include "php_serial.class.php"; //Initialize the class $serial = new phpSerial(); //Specify the serial port to use... in this case COM1 $serial->deviceSet("COM1"); //Set the serial port parameters. The documentation says 9600 8-N-1, so $serial->confBaudRate(9600); //Baud rate: 9600 $serial->confParity("none"); //Parity (this is the "N" in "8-N-1") $serial->confCharacterLength(; //Character length (this is the "8" in "8-N-1") $serial->confStopBits(1); //Stop bits (this is the "1" in "8-N-1") $serial->confFlowControl("none"); //Device does not support flow control of any kind, //so set it to none. //Now we "open" the serial port so we can write to it $serial->deviceOpen(); //Issue the appropriate command according to the serial relay //board documentation if ($_GET['action'] == "on") { //to turn relay number 1 on, we issue the command for ($x = 1; $x<20; $x++) //loops output $serial->sendMessage("3"); } else if ($_GET['action'] == "off") { //to turn relay number 1 off, we issue this command for ($x = 1; $x<20; $x++) //loops output $serial->sendMessage("2"); } //We're done, so close the serial port again $serial->deviceClose(); }?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Serial Control Test</title> </head> <body> <h1>Serial Control Test</h1> <p><a href="<?=$_SERVER['PHP_SELF'] . "?action=on" ?>"> Click here to turn the system on.</a></p> <p><a href="<?=$_SERVER['PHP_SELF'] . "?action=off" ?>"> Click here to turn the system off.</a></p> </body> </html> Thanks for your help guys!
  9. I have a simple category table in which 5 or 6 names are there. Now I want to retrieve them. When I connect to mysql database in procedural way, the while loop is working great, giving nice output. But when I go through a class and trying to retrieve the data, it stops after giving the first table name. My procedural code is here: mysql_connect("localhost", "root", ""); mysql_selectdb("12reach"); $cat = mysql_query("SELECT * FROM `category` LIMIT 0 , 30"); if (!$cat){ die ('Error'); } while ($row = mysql_fetch_array($cat)) { extract($row); echo $row['name'].'<br>'; } It works fine. Giving six category name. But problem begins with the following code: I have two classes and a php file where I created an instance of category class and trying to get the category table names one by one. class ConnectClass { private $_connection; public function getConnect() { $this->_connection = mysql_connect("localhost", "root", ""); if (mysql_errno()) { throw new RuntimeException('Cannot access database: '.mysql_error()); } else { mysql_selectdb("12reach", $this->_connection); } } include 'ConnectClass.php'; class CatClass extends ConnectClass{ public function getcat() { $cat = mysql_query("SELECT * FROM `category` LIMIT 0 , 30"); if (!$cat){ die ('Error'); } while ($row = mysql_fetch_array($cat)) { extract($row); return $row['name'].'<br>'; } } } include 'CatClass.php'; $obj=new CatClass(); $obj->getConnect(); echo $obj->getcat(); Probably while loop is working inside the class. As I want to return the last name of the category table, I can get it placing it outside the loop. But if I want the full name list, it does not work in object oriented format. Any idea, where is my fault?
  10. Good afternoon everyone, and happy holidays! Although my membership might not qualify as "new" to this forum, I've never used my account here before but today I think I finally found a reason to! I'm trying to exclude four (4) values from array, which will then echo the remaining values into a drop-down box on a form. Here is the contents of the array: Array ( [0] => stdClass Object ( [id] => 22 [icao] => CYQM [name] => Greater Moncton International Airport - CHARTER [country] => Canada [lat] => 46.1122 [lng] => -64.6786 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [1] => stdClass Object ( [id] => 19 [icao] => EINN [name] => Shannon International Airport - CHARTER [country] => Ireland [lat] => 52.702 [lng] => -8.92482 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [2] => stdClass Object ( [id] => 16 [icao] => KAUS [name] => Austin-Bergstrom International Airport [country] => United States [lat] => 30.1945 [lng] => -97.6699 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [3] => stdClass Object ( [id] => 9 [icao] => KDEN [name] => Denver International Airport [country] => United States [lat] => 39.8583 [lng] => -104.667 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [4] => stdClass Object ( [id] => 2 [icao] => KLAS [name] => McCarran International Airport [country] => United States [lat] => 36.0827 [lng] => -115.154 [hub] => 1 [fuelprice] => 0 [chartlink] => ) [5] => stdClass Object ( [id] => 5 [icao] => KLGB [name] => Long Beach Airport [country] => United States [lat] => 33.8175 [lng] => -118.152 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [6] => stdClass Object ( [id] => 14 [icao] => KOAK [name] => Metropolitan Oakland International Airport [country] => United States [lat] => 37.721 [lng] => -122.222 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [7] => stdClass Object ( [id] => 10 [icao] => KPDX [name] => Portland International Airport [country] => United States [lat] => 45.5887 [lng] => -122.598 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [8] => stdClass Object ( [id] => 3 [icao] => KPHX [name] => Phoenix Sky Harbor International Airport [country] => United States [lat] => 33.4359 [lng] => -112.01 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [9] => stdClass Object ( [id] => 12 [icao] => KRNO [name] => Reno/Tahoe International Airport [country] => United States [lat] => 39.4991 [lng] => -119.768 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [10] => stdClass Object ( [id] => 4 [icao] => KSAN [name] => San Diego International Airport [country] => United States [lat] => 32.7334 [lng] => -117.188 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [11] => stdClass Object ( [id] => 17 [icao] => KSAT [name] => San Antonio International Airport [country] => United States [lat] => 29.5338 [lng] => -98.47 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [12] => stdClass Object ( [id] => 6 [icao] => KSEA [name] => Seattle-Tacoma International Airport [country] => United States [lat] => 47.449 [lng] => -122.309 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [13] => stdClass Object ( [id] => 8 [icao] => KSFO [name] => San Francisco International Airport [country] => United States [lat] => 37.6188 [lng] => -122.376 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [14] => stdClass Object ( [id] => 15 [icao] => KSJC [name] => San Jose International Airport [country] => United States [lat] => 37.3619 [lng] => -121.929 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [15] => stdClass Object ( [id] => 11 [icao] => KSLC [name] => Salt Lake City International Airport [country] => United States [lat] => 40.7884 [lng] => -111.978 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [16] => stdClass Object ( [id] => 7 [icao] => KSMF [name] => Sacramento International Airport [country] => United States [lat] => 38.6952 [lng] => -121.592 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [17] => stdClass Object ( [id] => 13 [icao] => KTNT [name] => Dade-Collier Training Airport - CHARTER [country] => United States [lat] => 25.862 [lng] => -80.8967 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [18] => stdClass Object ( [id] => 18 [icao] => LTAI [name] => Antalya International Airport - CHARTER [country] => Turkey [lat] => 36.8987 [lng] => 30.8005 [hub] => 0 [fuelprice] => 0 [chartlink] => ) ) 1 As you can see, it's one (1) array that's broken up into a separate stdClass Object() array of some sort. My goal here is to exclude the following [id] values from the set of arrays above: 13, 18, 19, 22 The problem is that each array key (ex. [1], [2], [3]) from the first array will change when the contents of the array is increased over time. Therefore, I cannot simply exclude array keys [1], [2], [17], [18] Here's the code I'm working with now: <div id="depapttab"> <p>Select your departure airport:</p> <select id="depicao" name="depicao"> <option value="">Select All</option> <?php if(!$depairports) $depairports = array(); foreach($depairports as $airport) { if($depairports->id != array(13,18,19,22)) { echo '<option value="'.$airport->icao.'">'.$airport->icao.' - '.$airport->name.'</option>'; } } ?> </select> <input type="submit" name="submit" value="Find Flights" /> </div> I just don't know how to include that darn stdClass Object() in my if() statement. If someone could lend a hand, it'd be much appreciated! Thanks in advance!
  11. Hello: Any suggestions how to use all variables of a methods inside an array to apply another method on each one? fuction fn0(){....}//end fn0 function fn1($x1,$x2,$x3,$x4){ $mAr=array($x1,$x2,$x3,$x4); foreach($mAr as $val){ $this->fn0($val); }//end foreach }//end fn1 In reality I have like $x12. Thanks.
  12. I am using parent::__construct() in almost every classes to connect Mysql DB. Example class class secondClass extends dbconnect { public function __construct() { parent::__construct(); dbconnect class class dbconnect { private $mysqli_handler; public function __construct() { try { mysqli_report(MYSQLI_REPORT_STRICT); $this->mysqli_handler = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DBNAME); } catch (mysqli_sql_exception $e) { throw new Exception('Error: Could not make a database link using ' . DB_USERNAME . '@' . DB_HOSTNAME . '!'); } if ($this->mysqli_handler->connect_error) { trigger_error('Error: Could not make a database link (' . $this->mysqli_handler->connect_errno . ') ' . $this->mysqli_handler->connect_error); } $this->mysqli_handler->query("SET NAMES 'utf8'"); $this->mysqli_handler->query("SET CHARACTER SET utf8"); $this->mysqli_handler->query("SET CHARACTER_SET_CONNECTION=utf8"); $this->mysqli_handler->query("SET SQL_MODE = ''"); $this->mysqli_handler->query("SET time_zone = 'Asia/Kolkata'"); } Is this create multiple instance of mysql dbconnection? I am frequently getting mysql connection error on my shared hosting. If so how to avoid? I am using PHP Version 7.4.16, some detailed explanation will be useful for me as I am using like this for many projects. Thank you for your time. Prabakaran
×
×
  • 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.