Jump to content

rwhite35

Members
  • Posts

    159
  • Joined

  • Last visited

Everything posted by rwhite35

  1. Sorry correction to the above: // does work echo "Team Name: " . $lrow['rteamname'] . ", Season: " . $lrow['season']; //does work echo "Team Name: $lrow[rteamname], Season: $lrow[season]"; // doesn't work echo "Season: $lrow['season'], ..."; regular scalar variables like $teamname wouldn't require concatinating or escaping when using double quotes around the echo statement. Mixed quotes like above do require one syntax or the other.
  2. Notice the syntax Requinix is using with your associative array key names. You need quotes around the key name. echo "Season: $lrow['season'], League: $lrow['league'], Team Name: $lrow['rteamname'], First Name: $lrow['firstname'], Last Name: $lrow['lastname']"; Note you can only output your variables without concatinating a long string when your variables are enclosed in double quotes: // doesn't work echo "Season: $lrow["season"], ..."; // doesn't work echo 'Season: $lrow['season'], ...'; // does work, concatinated string echo "Season: " . $lrow["season"] . ", ..."; //does work, concatinated string echo 'Season: ' . $lrow['season'] . ', ...'; // does work, mixed quotes echo "Season: $lrow['season'], ..."; Finally, to make sure your array has value use var_dump($array_name) or print_r($array_name) to output the arrays content. Good Luck rwhite35
  3. This works great. <?php $qparams = array(); if($_POST) { $skus = $_POST['rec']; foreach($skus as $key=>$value) { $qparams[] = array($key, $_POST['ponumb'], $_POST['strnbr']); } } echo "<pre>"; print_r($qparams); echo "</pre>"; ?> <html> <head> <title>Testing HTML Array</title> </head> <body> <form action="", method=post> <fieldset><label>Test Form</label><br> 1769057 <input type="radio" name=rec[1769057] selected> 1768743 <input type="radio" name=rec[1768743] selected> <input type="text" name="ponumb" value="D000000034"> <input type="text" name="strnbr" value="100"><br> <input type="submit" value="submit"><br> </fieldset> </form> </body> </html> outputs Array ( [0] => Array ( [0] => 1769057 [1] => D000000034 [2] => 100 ) [1] => Array ( [0] => 1768743 [1] => D000000034 [2] => 100 )) Thanks! rwhite35
  4. Hey Jacques, Thank you for the reply. I've coded up mac_gyvers answer and it works great. I think it is similar to what you are suggesting too. Later, Ron
  5. Thanks mac_gyver, Ill try that and post the result.
  6. Hello, Have an associative array of variable length and variable key names. The POST array can have the following structure, where [rec_n] can have one or many elements. : $_POST Array ( [rec_1769057] => on [rec_1768743] => on [ponumb] => D000000034 [strnbr] => 100 ) The 'n' is a variable SKU number and concatenated from a select statement. There are thousands of SKUs. PONUMB and STRNBR are static and will always be at the end of the array. I have an algorithm for slicing this array into two separate arrays. skuitems Array ( [rec_1769057] => on [rec_1768743] => on ) postrnbr Array ( [ponumb] => D000000034 [strnbr] => 100 ) The two arrays are then assigned to a $params array one for each update statement... $params Array ( [0] => Array ( [0] => 1768743 [1] => D000000034 [2] => 100 ) [1] => Array ( [0] => 1769057 [1] => D000000034 [2] => 100 )) I would like to accomplish the above in one go... At present the solution has and O(2) notation. Here is the algorithm that works, but seems clunky to me. if( isset($postar) && is_array($postar)) { // first order of mag. $cnt = count($postar) - 2; // total minus last two elements $postrnbr = array_slice( $postar, -2, 2 ); // always ponumb and strnbr $skuitems = array_slice($postar, 0, $cnt); // will be one or more sku items $skukeys = array_keys($skuitems); $qparams = array(); //bind params for update statement foreach($skukeys as $sku) { // second order of mag. $skusplit = explode("_",$sku); // ie Array( [0]=>rec, [1]=>1234545 ) $qparams[] = array($skusplit[1], $postrnbr['ponumb'], $postrnbr['strnbr']); } } Thanks in advance! rwhite35
  7. Have a Zend Framework 2.4 connection factory that needs to establish a connection with an AS400 iSeries database. The connection has to be made this way bcuz there are multiple test environment and the factory needs to accommodate each. The method is using Zend\Db\Adapter\Adapter and I pass that class an array of database connection parameters. At issue: Zend\Db\Adapter doesn't accept the relational database (directory) name. I'm assuming that since the driver is PDO_IBM, there would be some expectation of a field for explicitly defining the name for the directory. Here is the method: public function conn($dbs) { $this->adapter = new Adapter(array( 'driver' => $dbs['db']['driver'], 'dbname' => $dbs['db']['dbname'], 'username' => $dbs['db']['username'], 'password' => $dbs['db']['password'], 'hostname' => $dbs['db']['hostname'], 'port' => $dbs['db']['port'], )); var_dump($this->adapter); return $this->adapter; } Adapter is an alias for \Zend\Db\Adapter\Adapter And here is the object that gets created. ["driver":protected]=> object(Zend\Db\Adapter\Driver\Pdo\Pdo)#224 (4){ ["connection":protected]=>object(Zend\Db\Adapter\Driver\Pdo\Connection)#225 (6) { ["driver":protected]=> *RECURSION* ["profiler":protected]=> NULL ["driverName":protected]=> string(3)"ibm" ["connectionParameters":protected]=> array(6) { ["driver"]=> string(7) "PDO_IBM" ["dbname"]=> string(7) “<relational_database_name>” ["username"]=> string(3) “<user_name" ["password"]=> string(3) “<password>" ["hostname"]=> string(9) "127.0.0.1" ["port"]=> string(3) "446" } I can instantiate the connection object using and query the database fine with: $conn = new \Zend\Db\Adapter\Adapter( ); // using Pdo=ibm:<relational_database_name> And here is the error Connect Error: SQLSTATE=42705, SQLConnect: -950 Relational database dbname=<rdn>;hos not in relational database directory. Any thought (about this topic) are greatly appreciated. Regards,
  8. Have you tried setting xhr.open( ) third argument to false? Since XMLHttpRequest default behavior is asynchronous, it may be that the larger file are taking to long to process. Setting XMLHttpRequest() to false (or synchronous) causes the save.php to completely run before the ready state changes, which in turn complete the request process. you'll also need to incorporate the readyState and Status in to your function. It would look something like: xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) { console.log("done"); } }
  9. Yep this ultimately was the problem. A sub class (not SiteNavigation) was not properly getting instantiated due to a typo in an extended data class... VERY FRUSTRATING trying to track down bugs when they are three objects deep. What bubbles up isn't typically the correct problem. I was getting a path errors. Eventually (after a lot of trial and error) I created a test script to load each class individually. It was through that test script the typo was revealed... Thanks again.
  10. Thanks for the reply requinix! The way I called serialize() was incorrect - fixed that now - thanks! The service manager runs after all classes have been autoloaded and I've confirmed that I have valid objects at this point in the service manager process. Im expecting serialize() to recursively "serialize" each sub class. But when I pass $regObj through serialize(), only the parent RegistryClass is being serialized. error_log("RegistryClass Serialized: " . $RegClassSerial); // outputs C:13:”RegistryClass”:2:{N;} Here is the RegistryClass relevant code: class RegistryClass implements Serializable { private $data; private $regList = array(); /* instantiates the singleton, add sub classes to regList with set(), etc */ public function serialize() { return serialize($this->data); // where recursion is expected } public function unserialize($data) { $this->data = unserialize($data); } public function getData() { return $this->regList; } To test the theory that serialize() isn't recursively serializing each sub class, I've hacked a work around that does this manually. And here is that code: $regObj = RegistryClass::getInstance(); /* adds sub classes, see code in initial post */ $serial = serialize($regObj); /* * here's the hack to manually force serializing each sub class * by cloning the serialized string and appended the sub classes */ foreach($regObj->getData() as $obj) { if(is_a($obj, $className)) { $serial .= serialize($obj); } } $_SESSION['RegistryClass'] = $serial; The hack code produces a string that looks like: error_log("RegistryClass Sub Class Serialized: " . $serial); // RegistryClass Serialized: C:13:"RegistryClass":2:{N;}O:14:"SiteNavigation":2:{s:13:"... And finally, when the serial string from $_SESSION['RegistryClass'] is assigned and unserialized(), the parent class is picked up but not the subs. Again, no recursion. // module/view/Index.phtml $serialized = $_SESSION['RegistryClass']; // echo $serialized //C:13:”RegistryClass”:2:{N;}O:14:"SiteNavigation":2:{s:13:"*siteConfig";N;s:8:"*route";N;} $newObj = unserialize($serialized); print_r($newObj); /* * outputs * RegistryClass( * [data:RegistryClass:private] => * [regList:RegistryClass:private] => Array( ) * ) */ As you see from above, regList is empty. Where I'm expecting SiteNavigation. Thanks again for the feedback, I appreciate your insight.
  11. So I have a registry class that holds sub class instances. When the application loads a module, the registry class needs to make sub class functionality available to the module. There's an autoloader in place, I just need the class instances. A service manager should load the registry class with sub classes. Service manager RegistryClass has this prototype at the end of the process: // hash table of registry properties and classes // SiteNavigation example is one sub class RegistryClass Object( [data:RegistryClass:private] => [regList:RegistryClass:private] => Array ( [SiteNavigation] => SiteNavigation Object ( [siteConfig:protected] => [route:protected] => 
 ) ) ) There are several MVC scripts in the module that require different things. However, when the script (ie module controller) picks up the Registry object, it's hash table (regList) is empty. // empty table, empty belly RegistryClass Object ( [data:RegistryClass:private] => [regList:RegistryClass:private] => Array ( ) ) I've tried using the built in PHP interface Serializable however, it's producing incomplete PHP objects when I call unserialize() method. Called from a module script - that looks like: $newObj = unserialize($serialized); // Registry appears fine, however, SiteNavigation is incomplete RegistryClass Object ( [data:RegistryClass:private] => [regList:RegistryClass:private] => Array ( [SiteNavigation] => __PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name] => SiteNavigation [siteConfig:protected] => [route:protected] => ) ) ) Here is a snip from the service manager which 1. instantiates a singleton registry class 2. instantiates the sub classes. $regObj = RegistryClass::getInstance(); // Singleton class holds instances of sub classes in hash table /* * set() method simply assigns sub class names as key and object instance as value to regList */ if(class_exists($className)) { $regObj->set($className, new $className); } /* * now serialize and assign to session, RegistryClass implements Serializable */ $_SESSION['RegistryClass'] = $regObj->serialize($regObj); It seems like the sub classes (ie SiteNavigation) doesn't serialize. Error log output only C:13:"RegistryClass":2:{N;}). Any thoughts are appreciated.
  12. In addition to QuickOldCar's answer, your markup is different then what Schema.org defines as a price object. Check out the http://schema.org/price Price description. Click on the Microdata tab for example markups. You may want: <span itemprop="priceCurrency" content="USD">$</span><span itemprop="price" content="1000.00">1,000.00</span> <link itemprop="availability" href="http://schema.org/InStock" />In stock
  13. It looks like you're using a framework and it has a helper method called groups_helper. Does the frameworks groups_helper have a method to do what you want? Also have you var_dumped the $user array? Does $user have some element that id's which group(s) they belong to? Example(pseudocode): //pseudocode $user = array( 'group_id' => array ( 'a_group' => 123, 'b_group' => 456, ), ) Since you're using some framework, you'll need to fully understand that frameworks methods in order to change your code above.
  14. Use the download attribute of <a> tag. <a href="<?php echo $link?>" download="<?php echo $filename?>">Download File</a>
  15. One thing is your Ternary operator. //change this $name = isset($_POST['name']) ? $_POST['name'] : ""; //to this $name = (isset($_POST['name'])) ? $_POST['name'] : ""; I wasn't able to see where you were passing PHP var to Javascript, however you can try this, it would be cleaner then trying to assign JQuery selector value. var name = <?php echo htmlspecialchars(json_encode($name), ENT_NOQUOTES); ?>;
  16. Try this. <blink> is unreliable and probably deprecated. So <marquee> would be another option. date_default_timezone_set("America/New_York"); $stored_date1 = "2015-08-01 01:30:00"; // in the past $timestamp1 = strtotime($stored_date1); $stored_date2 = "2015-08-12 03:00:00"; // in the future $timestamp2 = strtotime($stored_date2); function evalStoredTime($t) { $curtime = time(); $calculated = $t + 86400; // + 24 hours if($calculated >= $curtime) { echo "The stored date/time plus 24 hours is in the future."; } else { echo '<marquee behavior="scroll" bgcolor="#00CCCC" loop="-1" width="40%">The stored date/time plus 24 hours is in the past.</marquee>'; } } echo " Date/time 1: " . evalStoredTime($timestamp1); echo "<br>"; echo " Date/time 2: " . evalStoredTime($timestamp2);
  17. How is your Created_Date stored before calling getdate() function? That function is returning YYYY-mm-dd HH:mm:ss. You could try strtotime() which will attempt to convert your string to a Unix timestamp. Once in Unix timestamp, you can apply some algorithm that will: 1. Calculate Created_Date plus 24 hours 2. compare current time() to Calculated (Created_Date + 24 hours) time. 3. If current time() is greater than Calculated time, echo out some message 4. else do nothing
  18. After a lot of reading and experimentation, its working. The problem seems to be in the modules router. Using the above router in Guestbook/config/module.config.php, the ServiceManager was registering everything, but wasn't finding the module resources. After reading through the ZF2.4 manual here I've changed the router to: 'router' => array( 'routes' => array( 'guestbook' => array( 'type' => 'Segment', 'options' => array( 'route' => '/[:controller[/:action]]', 'defaults' => array( '__NAMESPACE__' => 'Guestbook\Controller', 'controller' => 'Guestbook', 'action' => 'index', ), 'constraints' => [ 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', ] ), // options ) // guestbook ) // routes ), // router This router setup is serving the page as I would have expected.
  19. To help drill the problem down more. The ViewModel method renders the html. Here is the machinery involved. /view/guestbook/guestbook/index.phtml <?php $title = 'My Guestbook'; $this->headTitle($title); ?> <h1><?php echo $this->escapeHtml($title); ?></h1> <p> <a href="<?php echo $this->url('guestbook', array('action'=>'add'));?>">Add</a> </p> <table class="table"> <tr> <th>Title</th> <th>Artist</th> <th> </th> </tr> <?php //$guestbooks array defined in GuestbookController class foreach ($guestbooks as $guestbook) : ?> <tr> <td><?php echo $this->escapeHtml($guestbook->user);?></td> <td><?php echo $this->escapeHtml($guestbook->message);?></td> <td> <a href="<?php echo $this->url('guestbook', array('action'=>'edit', 'id' => $guestbook->id));?>">Edit</a> <a href="<?php echo $this->url('guestbook', array('action'=>'delete', 'id' => $guestbook->id));?>">Delete</a> </td> </tr> <?php endforeach; ?> </table> /src/Guestbook/Controller/GuestbookController.php namespace Guestbook\Controller; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; class GuestbookController extends AbstractActionController { protected $guestbookTable; public function indexAction() { return new ViewModel(array( 'guestbooks' => $this->getGuestbookTable()->fetchAll(), )); } //rest is omitted for brevity /src/Guestbook/Model/Guestbook.php namespace Guestbook\Model; class Guestbook { public $id; public $user; public $message; public function exchangeArray($data) { $this->id = (isset($data['id'])) ? $data['id'] : null; $this->user = (isset($data['user'])) ? $data['user'] : null; $this->message = (isset($data['message'])) ? $data['message'] : null; } } /config/module.config.php return array( 'controllers' => array( // list of all module controllers 'invokables' => array( // [controller_reference] = [controller_string] 'Guestbook\Controller\Guestbook' => 'Guestbook\Controller\GuestbookController', ), ), //map actions to URL patterns with router action->route->url 'router' => array( 'routes' => array( 'guestbook' => array( 'type' => 'segment', 'options' => array( 'route' => '/guestbook[/:action][/:id]', 'constraints' => array( 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 'id' => '[0-9]*', ), 'defaults' => array( 'controller' => 'Guestbook\Controller\Guestbook', 'action' => 'index', ), ), ), ), ), // defines location of module viewer scripts 'view_manager' => array( 'template_path_stack' => array( 'guestbook' => __DIR__ . '/../view', ), ), ); Thanks.
  20. Work through the Skeleton Application::Module section for ZF2. Application is displaying the default ZF2 landing page (module/Application/view/application/index/index.phtml). And I've set up a test/ directory in my module then ran phpunit test. The test checks out and it returns OK (7 tests, 16 assertions). As far as I can tell, the application through Database and Modules is setup correctly. However when I go to load the module page, I get a blank page with one line of text: missing.html. Setup: Module Name: Guestbook App Path: octoberblue.net/guestbook Virtual Host: guestbook.octoberblue.net Directory(httpd-vhosts.conf): guestbook/public mod_rewrite enabled .htaccess configured Current file structure My module name is Guestbook and I'm porting the ZF1 guestbook Skeleton project to ZF2. Error_log when loading guestbook.october.net/guestbook (the suggested method) File does not exist: /opt/local/apache2/htdocs/octoberblue/guestbook/public/guestbook BTW, the framework is returning the error/text. If I try and load the module viewer (view/guestbook/guestbook/index.phtml) by entering the absolute real path in the browser address bar, I get a different error in the error_log, that error is: .htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration Any thoughts appreciated. Thanks in advance.
  21. Perhaps I should have typed "with each new page load" instead of iteration. But I get where you're heading, page 1 * 5 (5); page 2 * 5 (10); page 3 * 5 (15) etc. But your still making multiple trips to the data store with each page load, and that was really my point. An expensive proposition if you have lots of records and lots of traffic. For the sake of argument, if the first page instanced a multi-dim array of ALL records in one pull, the $records array could be passed along to the next page using a session. If this were a website with a lot of traffic (hundreds of request per hour) then the second option ($records-session) is likely the better. If only a couple request a day, I suppose either is fine.
  22. if you want to continue with the same logic as originally proposed, you can use the LIMIT $start, $end when $start is incremented by the number of post per page. If 5 post per page, $start would be 0, 5, 10, 15, 20 etc... and $end 4, 9, 14, 19 etc. SELECT * FROM articles ORDER BY id ASC LIMIT $start, $end; The issue with this though is performance. You would re-query the database with every iteration. I go back to my original post and work out the pagination using a multi-dim array. Its less system resources.
  23. It might help if you separate the two operations (concerns) and think about them as database and output. Try your code this way: <?php //head of script $blog = mysqli_query($con,"SELECT * FROM articles ORDER BY id ASC"); while( $row = mysqli_fetch_array($blog)) { $records[] = $row; } // $records prototype Array([0]=>Array(['id], ['title']...),[1]=>Array(['id'], ['title']..)) ?> <body> <div> <?php foreach($records as $array) { echo "<h1>".$array['title']."</h1>"; // continue the rest of your output echo '<a href="articles.php?id='.$array["id"].'"><button>Read More</button></a>'; } // close foreach loop ?> </div> </body> Additionally, when coded this way, you can test $records to make sure your query is returning what you expect: var_dump($records); // or use print_r($records);
  24. Are $parents and $searched two different arrays? I can't tell from your logic whether these are two different arrays or different dimension of a multi dim array. The multi dim array above has two dimensions. Is that your $parent (first dimension) and $searched (second dimension). If so, your outer and inner loops maybe confusing the logic. Maybe try a for loop on the inner to help keep things simpler and more manageable.
  25. Unless you are in the context of a class with an object, I think you're looking for this: foreach ($parents as $key=>$value) { // -> is for class pointers as in $this->object
×
×
  • 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.