spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » PHP » Page 1
Sorting using switch in php
Your first line of code : $sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'date'; is equivalent to : if (isset($_GET['sort'])) { $sort = $_GET['sort']; } else { $sort = 'date'; } Now it depends on what GET request you're sending when "Date" is clicked. According to your switch, you shoud receive ?sort=1 so the order is set to date ASC, else it will fall back to date DESC. Does that

Categories : PHP

Increase limit when using fputcsv
Some other things to consider upload_tmp_dir The temporary directory used for storing files when doing file upload. post_max_size Sets max size of post data allowed. This setting also affects file upload file_uploads Whether or not to allow HTTP file uploads.

Categories : PHP

Laravel 5.0 Model::create() method creates two rows in one form request
I'm using it exatly the way you do, and didn't happen to me. I don't know if this have any relationship, but in your model, the fillable var you need to put ['title', 'description', 'category'] for working correctly. Or, at less, ['title'] that is the only required value. Why you don't put dd($request); and show us what is inside.

Categories : PHP

Cakephp doesn't read browser cookie
Try adding 'Cookie' to your components (in the controller class, a parameter should be named components): var $components = array('Cookie'); See here: http://book.cakephp.org/1.3/en/The-Manual/Core-Components/Cookies.html

Categories : PHP

How can I implement variable width look behind regex to get a list of items?
Use the below regex and get the count from group index 1 and fruit name from group index 2. (?:^fruits|(?<!^)G)h*K(?<count>d*)h*(?<fruit>w*) DEMO

Categories : PHP

prepared statement with Eloquent ORM / laravel
Eloquent does the PDO style prepared statements behind the scenes to protect against things like sql injection. Eloquent models also protect against mass assignment by default. An exception will be thrown unless you specifically note the columns of the database that should be guarded or the inverse (the ones that should be fillable). http://laravel.com/docs/4.2/eloquent#mass-assignment If you wa

Categories : PHP

Smarty - How to store part of string from url to variable?
You cannot call PHP functions from Smarty like this. Do the assignment from the PHP code: $smarty = new Smarty(); $pieces = explode("/", $_SERVER['REQUEST_URI']); $smarty->assign('url_catname', $pieces[3]); $smarty->display('blah-blah.tpl');

Categories : PHP

Apache + php-fpm : headers stripped?
That's just because you a saying that it's proxy server, which means for security reasons that's purged. as far as I can remember it's not really possible easily. Anyway my suggestion is to use Nginx with PHP-FPM and if you need to use the Apache use the php module for apache as it's designed this way. Hope it helped answering your question.

Categories : PHP

php and mysql problems with updating two tables, and inserting into two tables with one button
There are a few things wrong with your code. There's VALUES ('$user_id', '$orderIn_id '$invoiceIn_total', ^^ is missing a quote and a comma do VALUES ('$user_id', '$orderIn_id', '$invoiceIn_total', same thing for VALUES ('$user_id', '$orderOut_total '$invoiceOut_total', ^^ do VALUES ('$user_id', '$orderOut_total', '

Categories : PHP

Wordpress WP Query display all posts with specific tag
Try: $query = new WP_Query( 'posts_per_page=-1&tag=cooking' ); echo '<pre>' . print_r( $query->posts, 1 ) . '</pre>'; // this line is for debugging purposes only. You are missing the ampersand '&'. See: http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters

Categories : PHP

Contact Form Disappearing When Div is Set?
The exit() function prevents the rest of the script from executing, which includes your form and footer. Remove it and it will work. if (mail($to, $subject, $Message, $headers)) { echo '<div id="thanks">Mail sent</div>'; } else { echo 'Mail Failed'; } As Raidenance pointed out, if someone refreshes this page after posting the form it will resend the email address. A better s

Categories : PHP

Magmi removing product relations on import
The "admin" store is a value that tells => consider all following values to be "common" to all stores. Depending on the order of import of your files (or lines in the CSV if you are using a single file), the "admin" will also assume "remove all previous store specific associations for the data of this line" (for all data that may have a store view scope). So it's just a "import" partitioning pro

Categories : PHP

PHP Check if time is between two times regardless of date
Try this: function checkTime($From, $Till, $input) { if ($input > $From && $input < $Till) { return True; } else { return false; }

Categories : PHP

Symfony2/Twig/Bootstrap: How to customize DeleteForm Button
Change: {{ form_widget(delete_form.submit, { 'label': 'Delete' }, { 'attr': {'class': 'btn btn-default', 'type' => 'button'} }) }} To: {{ form_widget(delete_form.submit,{ 'label': 'Delete' }, { 'attr': {'class': 'myOwnClassSelectorsHere', 'type': 'button'} }) }} Use your CSS selectors inside the attr declaration and it will use any styles you have applied to that class. Where { 'attr':

Categories : PHP

Submit Input field on page refresh
Using window.location.href = sTargetURL; Will just redirect the page, it will not submit it. To submit the form use this instead. document.getElementById("form1").submit(); Oh and give the form an id as well <form id="form1" name="form1" method="POST" action="dashboard.php"> Also you dont have to shout all your HTML tags and attributes.

Categories : PHP

PHP copy performance with larger video files
Moving is always much faster than copying data- as the OS only needs to adjust the file's location, not recreate it. I would recommend moving the file and you should see a nearly instant response from the move command. The connection speed does not impact the performance of the PHP, as the PHP is run server-side. The PHP will respond at the same speed regardless of the user's connection. The best

Categories : PHP

Installing Laravel in a subdirectory
I might not have understood your question properly but here is my solution. Go to /bootstrap/paths.php and change to: return array( 'app' => __DIR__.'~username/../app', 'public' => __DIR__.'~username/../public', 'base' => __DIR__.'~username/..', 'storage' => __DIR__.'~username/../app/storage', ) I'm not sure if this will work. I haven't tried it.

Categories : PHP

retrieving from database into table in php
header("Content-type: application/json; charset=utf-8"); That's... not JSON data. That's HTML. For example: echo "<table>"; The default Content-type is probably HTML, so you can just remove the header line entirely. If you want to be explicit, you can be: header("Content-type: text/html; charset=utf-8"); Basically what's happening is that you're explicitly telling the browser not

Categories : PHP

How do I start the week on monday?
Here you go man - week start with monday and days are correct. <?php $year = 2015; echo "<table cellspacing=10 border=0>"; echo "<tr><td align=center colspan=3 class='topic'>$year Yearly Calendar</td></tr>"; for($ti=0;$ti<12;$ti++) { $month = $ti+1; if($ti%3==0) echo "<tr>"; echo "<td valign='top'>"; echo "<span class='mo

Categories : PHP

Why are my params not showing up in the url?
If you want the browser to display the new URL then you need to perform a HTTP redirect as the forward plugin will dispatch to the new controller in the same request. Replace the forward call with a call to the redirect plugin. return $this->redirect()->toRoute('home/results/route/name'); This will also solve your addition issue where the HTTP method is still set as POST (as the redirec

Categories : PHP

Can I get non-shared objects via the service locator using an abstract factory?
By default all services are shared, it make no difference how they are created. The first call to $serviceManager->get('foo') will create the instance of the service and then store that value in memory, keyed by it's canonical name. The second call to $serviceManager->get('foo') will match this stored value and return the same instance. The obvious exception to the above is if you disable

Categories : PHP

recursive function with unique name in php
$sql = $wpdb->prepare("SELECT * FROM mm_goats WHERE id = %d", $goat_id); ^^^^^^^ You fetch the indicated ID, which then is used in the recusrive call: generate_tree($row2['id']); ^^^^^^^^^^^ So you just keep fetching information about the SAME goat on every recursive iteratio

Categories : PHP

CodeIgniter 2.2.0 + ION_Auth + Restful API
For digest authentication the library function should return already stored md5(username:restrealm:password) for that username | E.g: md5('admin:REST API:1234') = '1e957ebc35631ab22d5bd6526bd14ea2' I tried and I passed : try to return MD5('$login:REST API:$password'); where $login is your login et $password is the password

Categories : PHP

PHPExcel copy Worksheet without fx
You can retrieve only the data : $objReader = new PHPExcel_Reader_Excel2007(); $objReader->setReadDataOnly(true); $objPHPExcel = $objReader->load("myworkbook.xlsx"); Or you can get the calculated values of cells : $objPHPExcel->getActiveSheet()->getCell("A2")->getCalculatedValue();

Categories : PHP

PHP - Convert random colour generator to select from predefined colours
$colors[0] = "color:#FFFFFF"; etc.. Fill an array with strings of the colors, then use: $key = mt_rand(0, 5); to generate a random key for you, then simply request that key from your array. $color = $colors[$key];

Categories : PHP

How to get all checkout fields from WooCommerce?
i was facing the same issue . here's how i managed it . class my_checkout_fields_class { var $countries; function __construct() { $this->countries = new WC_Countries(); } } Now you can get billing and shipping fields respectively in this class. $billlingfields = $this->countries->get_address_fields( $this->countries->get_base_country(),'billing_'

Categories : PHP

Using jquery how to get json data via ajax method
I don't really know what you're trying to do, but a few comments: dataType is what you're expecting back from the server, not what you're sending. Use contentType. Try to return the ajax call and chaining them together with a done() function instead of embedding the success. This makes the code more readable. Stringify the request so that you're sending a json encoded string instead of a javasc

Categories : PHP

Successful message either by inserted values or rows affected
$Result1(TRUE) is an outright syntax error. $Result1 will be a query HANDLE as returned by mysql_query() upon success or a boolean false to signify failure. Never will it be a function. $Result1 = mysql_query(...); if ($Result1 === false) { die(mysql_error()); }

Categories : PHP

composer, laravel and 2 versions of PHP
During composer update, composer is calling the scripts in the composer.json file. For Laravel this file looks something like: "scripts": { "post-install-cmd": [ "php artisan clear-compiled", "php artisan optimize" ], "post-update-cmd": [ "php artisan clear-compiled", "php artisan optimize" ], "post-create-project-cmd": [ "php artisan ke

Categories : PHP

Running Magento Using Vagrant / Puphpet
SOLVED: In my case, PHP GD was not installed in the Vagrant config. So in the PHP section of my Puphpet config, i added: php: install: '1' version: '55' composer: '1' composer_home: '' modules: php: - cli - intl - mcrypt - gd pear: { } pecl: - pecl_http ini: display_errors: On error_reporting: '

Categories : PHP

Deploying Symfony2 from TravisCI to Heroku after successful build error blank screen
I think the problem is that in production environment uses a cached version of '%kernel.root_dir%'. Heroku build the slug in a directory like '/tmp/build...' but runs it in the directory /app. The only workaround that I found is to change the logic used to calculate the root directory. I changed my 'app/AppKernel.php' adding this method: public function getRootDir() { if (isset($_ENV['SYMFON

Categories : PHP

Property Status Duplicating Properties on WordPress Site
OK, following on from my comment I'll explain. There is probably a better way of achieving this by changing the meta_query arguments to make it more efficient (ie not pull out duplicates in the first instance) but what the link in my comments is doing is setting up a new empty array outwith the while loop, and then adding values to it as it iterates through the loop. In that example in the link

Categories : PHP

Parse HTML with PHP
Try looking into DOMDocument instead of regexing the HTML. With loadHTML() you can let PHP parse the HTML. Look at HTML DOM Document parsing for an example.

Categories : PHP

How to add PHP part inside PHP
use the string contatination operator - '.' - in order to append additional output (such as a function call) to the string. <?php if(is_page('Another page title')){ echo '<img src="/image-' . rand(...) . '.jpg">';}?>

Categories : PHP

How to handle long SMS text from Nexmo API properly?
Using a session to store the temporary sms parts would only work if there is an exchange of keys between the client and server with each HTTP request which identifies the session. In PHP, when you create a session and store a value inside $_SESSION a file is created on the server to store this data (unless you are using a DB session handler, in which case the session data is stored in a database

Categories : PHP

MySql - how can you create a unique constraint on a combination of two values in two columns
In MySQL, you can't use functions as the values for indexes. The documentation does not explicitly state this, however, it is a basic characteristic of an index to only support "fixed" data: Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. Generally, this

Categories : PHP

Block %%% in MySql query
From the mysql documentation: Character Description % Matches any number of characters, even zero characters _ Matches exactly one character Therefor you'll have to escape them in your $query variable. $query = str_replace(array('%', '_'), array('\%', '\_'), mysql_real_escape_string($_GET['query'])); However, I do not suggest you still use the mysql_* functions, as of PHP 5.5.0 the my

Categories : PHP

check if a two different string contain two different specific words in php
use strpos(): if((strpos($ttle, $key) !== false) && (strpos($lloc,$loc) !== false)) { //echo some thing } strstr() function Returns part of haystack string starting from and including the first occurrence of needle to the end of haystack. strpos() function Returns the position of where the needle exists relative to the beginning of the haystack string (independent

Categories : PHP

composer not parsing composer.json
Unfortunately, you can not do that with a vendor post-instal/update-scripts. BUT See how it is resolved in BraincraftedBootstrapBundle: They have a separate command to copy the icons I show that it can be added to composer.json. BraincraftedBootstrapBundle -> Installing Glyphicons

Categories : PHP


Recently Add
Html form redirect to a url
Sorting using switch in php
Increase limit when using fputcsv
Laravel 5.0 Model::create() method creates two rows in one form request
Cakephp doesn't read browser cookie
How can I implement variable width look behind regex to get a list of items?
prepared statement with Eloquent ORM / laravel
Smarty - How to store part of string from url to variable?
Apache + php-fpm : headers stripped?
php and mysql problems with updating two tables, and inserting into two tables with one button
Wordpress WP Query display all posts with specific tag
Contact Form Disappearing When Div is Set?
Magmi removing product relations on import
PHP Check if time is between two times regardless of date
Symfony2/Twig/Bootstrap: How to customize DeleteForm Button
Submit Input field on page refresh
PHP copy performance with larger video files
Installing Laravel in a subdirectory
retrieving from database into table in php
How do I start the week on monday?
Why are my params not showing up in the url?
Can I get non-shared objects via the service locator using an abstract factory?
recursive function with unique name in php
CodeIgniter 2.2.0 + ION_Auth + Restful API
PHPExcel copy Worksheet without fx
PHP - Convert random colour generator to select from predefined colours
How to get all checkout fields from WooCommerce?
Using jquery how to get json data via ajax method
Successful message either by inserted values or rows affected
composer, laravel and 2 versions of PHP
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.