php

How to manage an AJAX based 'like/dislike' feature?

I'd like to add a like/dislike-upvote/downovote-type feature to each one of the posts in the forum script I'm writing (much like the one here in SO). I'm having two difficulties trying to figure out how it can be done: 1) I can't figure out a db schema that'd do it efficiently. I could use a separate \likeordislike\ table to make a rela...

Looking for a new lightweight php editor for windows

Whats the most lightweight php editor out there for windows? other than notepad++ not looking for anything extreme,im just a 'hobby coder' been using notepad++ for 3 years and im just getting tired of it, want some new And what does it mean that a editor has "auto completing"? thanks a lot! ...

MVC architecture for front-end

Hi! I am writing application in PHP (+ MySQL database), but it gonna be mainly AJAX aplication. So, I am wondering, how to create frontend? Frontend also in MVC? Is it possible? ...

PHP Parse error: syntax error, unexpected T_STRING

Hi folks, I'm getting this syntax error and I know it's PHP 101, but I wouldn't know php if it hit me over the head with a curly bracket. Any help would be appreciated. Thanks <?php echo ($this->getProduct()->getCategory() ? $this->getProduct()->getCategory()->getName() : ‘no category’) ?> ...

MVC pattern and $_POST variables

Hi,I am building a php/mysql based framework and cms , and I got stucked into passing variables using post method , from a form located in one controller, to another controller. More exactly , i built a form for changing languages. this form is located in localhost/index/index, and when I select a language, it goes to http://localhost/ap...

How to set the message of the NotEmpty validator on a Zend_Form_Element?

I have a form element that I'm setting as required: $this->addElement('text', 'email', array( 'label' => 'Email address:', 'required' => true )); Since I'm setting required to true, it makes sure that it's not empty. The default error message looks like this: "Value is required and can't be empty" I tried setting the...

PHPUnit - test MVC controller with $_POST variable

I'm starting work with PHPUnit with Kohana. My application have many controllers which simply takes data from some form, validates and inserts/updates/deletes into/-/from database. How should I write a test cases for that. I know that if I want to test a function I write data provider function and just compare returned value with the ex...

PHP Comments # vs //

Lately I've been using # instead of // for doing single line comments inside my Code. However, I see must of the people prefer //. Is there a particular reason for preferring them instead of #? Performance? File weight? Anything? ...

No full-text support; must have effective mysql db search engine; where to find one?

I have asked several questions about Zend and its search functions. Now after further reading I have noticed that it requires FULL-TEXT indexes in the MySQL fields. My webhosting provider doesn't allow me to change anything in the my.ini (my.cnf) file, which holds information about minimum length of word to search full-text indexes an...

MySQL - A query based on another query

I write a lot of queries resembling the query example code below. I was wondering whether there was a more efficient code/script? $query1 ="SELECT * FROM table1 WHERE date >= '$todaysdate' "; $result1 = mysql_query($query1) or die ("Error in query: $query1. " . mysql_error()); if (mysql_num_rows($result1) > 0) { while($row1 = m...

Creating an array with $x elements in PHP

How would I create an array in PHP that has $x empty elements? The $x is unknown and varying value. For example, if I wanted to create an array of 3 elements, I could just do: $array = array(null,null,null); However, I don't know what $x is and there could be million elements, I need to do this automatically. ...

How to use call_user_func_array with an object with a __construct method in PHP

How could I use call_func_array to create a new object with a __construct method (with some not optional arguments). Here's the code: $urls = array( 'view' => array( 'view/(\d+)', array('controller' => 'test', 'action' => 'view'), array(1 => 'id'), ), ); foreach ($urls as $name => $args) { $route = ca...

Finding out the filename that called my function in PHP

How do I find out the filename of the script that called my function? For example, function sthing() { echo __FILE__; // echoes myself echo __CALLER_FILE__; // echoes the file that called me } ...

PHP substring extraction. Get the string before the first '/' or the whole string

I am trying to extract a substring. I need some help with doing it in PHP. Here are some sample strings I am working with and the results I need: home/cat1/subcat2 => home test/cat2 => test startpage => startpage I want to get the string till the first /, but if no / is present, get the whole string. I tried, substr($mystring, 0...

alerting user on other user login with jquery ajax

how can i alert the user already logged in for the new user logged in........suppose.... user1 one is currently logged in and user2 is offline. i want to alert user1 when user2 logged in............ how can i achieve this ...

What are the major differences between Python and PHP?

I know PHP a little. But Python is totally new for me. I only know it's something "similar", right? Or wrong? What are the differences I should know? ...

PHP with Netbeans or Eclipse?

I'm not looking for a "religious discussion" here, but I want to know the Pros and Cons of both development environments. I'm on the Mac, btw. ...

PHP: convert date into seconds?

I've a date like Tue Dec 15 2009. How can I convert it into seconds? ...

NetBeans and PHP on the Mac: How to set it up?

I'm new to this and want to start coding PHP with NetBeans. Is there a step-by-step instruction on how to set this up? ...

Problem with function call inside preg_replace.

Does not work, the $1-value is lost when calling the function: echo preg_replace('"\b(http://\S+)"', '<a href="$1">'.findTopDomain('$1').'</a>', $text); Works fine, outputs: stackoverflow.com echo preg_replace('"\b(http://\S+)"', '<a href="$1">'.findTopDomain('http://stackoverflow.com/questions/ask').'&lt;/a&gt;' , $text); I need t...