I need to do an advanced Google search, using their SiteSearch API. I’m currently using a string of the following format that is sent via curl to my search engine: $search_url = “http://www.google….
Tag: php
Creating a table with mysql, php and ajax (with jquery)
For my new project i want the so modern approach of not needing to reload a page on every database request. 🙂 I want the script to query the database and create a table with the query information. I have tried different scripts i have found on the internet. The one below was closest to my needs. index.php get…
Return data back to dispatcher from event observer in Magento
I have an extension for product registration that dispatches an event after the registration is saved. Another extension uses that event to generate a coupon for a virtual product if it is related to the registered product. I need to get back data on the generated coupon to send to the user in an email along …
Learning how to refactor PHP code
I’m using PHP 5.2.9 at the very moment. Is there a way to refactor this code this way it’s easier to read and better organized? Answer It depends on what exactly you mean by “compress”? Since you haven’t clarified you’re getting a basic response. Removing spaces: If you are…
symfony2: how to access service from template
If I created a service is there a way to access it from twig, without creating a twig.extension? Answer You can set the service a twig global variable in config.yml, e.g And in your template.html.twig file you can invoke your service this way: See here.
Creating a database connection class (PDO) and fetch data
I am new to OOP, so I am trying to learn how to create classes and use them. Currently I am trying to fetch data from my MySQL table. To create the connection with MySQL I am using PDO. I have …
sorting a column in a PHP array
I am trying to sort by a column(s) in the following data structure that I have built like this: This is a var_dump of the $entity_list data structure. How do I use asort() or ksort() on this structure? I think i should be using ksort(), as it works on a key. I have tried ksort($entity_list,’student_last…
LIKE query using multiple keywords from search field using PDO prepared statement
Site users use a search form to query a database of products. The keywords entered search the titles for the products in the database. The search works if a user enters a single keyword, but if multiple keywords are used the query does not execute. if: $keywords = ‘apple ipod’; $search = ‘%a…
How to save an HTML5 Canvas as an image on a server?
I’m working on a generative art project where I would like to allow users to save the resulting images from an algorithm. The general idea is: Create an image on an HTML5 Canvas using a generative …
Array to string conversion
What is the problem? Why can’t work? Array to string conversion…. Can anyone suggest how to reduce the number of lines of code in such a case? Answer