php

How to execute two mysql queries as one in PHP/MYSQL?

I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name LIKE '%prashant%' LIMIT 0, 10; SELECT FOUND_ROWS(); I want to execute both these queries in a single attempt. $result = mysql_query($query); But then tell me how I will handle each tables set separately. Actually in ASP.NET we uses datas...

Making sure http appears in a web address

I have people posting their website address but variations are posted such as: theirsite.com www.theirsite.com http://theirsite.com http://www.theirsite.com When I link to an address without http:// it takes the link as internal <a href="theirsite.com">their site</a> sending people to something like: http://mysite.com/thiersite.co...

Selecting random entry in MySQL with WHERE clause problem

Hi all, I'm running the following code to get a random entry from a dictionary: SELECT * FROM tbl_dict WHERE 1 ORDER BY RAND() LIMIT 1 This works great, but as soon as I expand there WHERE clause the query fails. What I need is something like... SELECT * FROM tbl_dict WHERE 1 and lock='0' ORDER BY RAND() LIMIT 1 Can anyone point o...

PHP safe_mode default value in PLESK 8.4 is ON. WHY?

Hi, I am wondering why is the default value of the PHP safe_mode ON in PLESK. I suspect it is a security issue but how exactly is this useful? p.s. As an inexperienced web-developer I spend some hours wondering why the .php files were downloaded instead of run on my server. The reason was that this php default safe_mode was ON and I fou...

Display Google Keywords that brought a user to the site

I am looking to display something like: Hello, you've reached this site by looking for [google keyword(s)] I'm pretty sure I've seen this done before but I am having troubles figuring out how to grab the keywords that were used to lead a user to my site. Anyone know the answer? ...

Good PHP Text Pagination

Hi folks, First post here. I'm working on an information warehousing site for HIV prevention. Lots of collaborators will be posting articles via a tinyMCE GUI. The graphic designers, of course, want control over page lengths. They would like automatic pagination based on the height of content in the page. Anyone seen AJAX code to m...

Using params['named'] in Cakephp

url: /contents/view/chapter:models/section:associations class ContentsController extends AppController { function view() { $this->params['named']; } } For example, I have the url and controller above and the goal is to use the key/value information from the url to query a database. How would I create a model to do ...

Catching type mismatches with PHP Soap Server

I have a PHP5 Soap Server running and I'd like to catch type mismatches but I don't think they're even getting into my code. What's happening is this, in my WSDL I've got (simplified): <complexType name="Publishing"> <all> <element name="EmailBlast" type="xsd:boolean"/> <element name="PublishRadius" type="xsd:int"/> </all> </comp...

passing parameters to php in a form?

I have the basic html form echoed through php: <html> <body> <?php if (isset($_GET["pk"])) { $pk = $_GET["pk"];} echo '<form action="up.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form>';...

Preferred method to store PHP arrays (json_encode vs serialize)

I need to store a multi-dimensional associative array of data in a flat file for caching purposes. I might occasionally come across the need to convert it to JSON for use in my web app but the vast majority of the time I will be using the array directly in PHP. Would it be more efficient to store the array as JSON or as a PHP serialized...

CodeIgniter: Create new helper?

Hi, I need to loop lot of arrays in different ways and display it in a page. The arrays are generated by a module class. I know that its better not to include functions on 'views' and I want to know where to insert the functions file. I know I can 'extend' the helpers, but I don't want to extend a helper. I want to kind of create a help...

What would my controller be in these scenarios in a mvc web application?

1) Where does the homepage of your website fit into "controllers"? I've seen some people use a "page" controller to handle static pages like, about, home, contact, etc., but to me this doesn't seem like a good idea. Would creating a distinct controller just for your homepage be a better option? After all, it may need to access multipl...

How to subtract two dates, ignoring daylight savings time in PHP?

I'm trying to calculate the number of days between two days, but I'm running into issues with Daylight Savings Time. Here's my code: function date_diff($old_date, $new_date) { $offset = strtotime($new_date) - strtotime($old_date); return $offset/60/60/24; } Works fine as long as the days are both within the same DST period: e...

Get PHP class property by string

How do I get a property in a PHP based on a string? I'll call it magic. So what is magic? $obj->Name = 'something'; $get = $obj->Name; would be like... magic($obj, 'Name', 'something'); $get = magic($obj, 'Name'); ...

Help me combine these conditions for determining if this list item begins with a new letter

Maybe I'm having a bad day, but I can't seem to combine these 2 conditions into 1. They obviously should be, because they output the exact same data. The following code creates a list with A-Z to act as anchor links, and is then meant to traverse an array in the format 'word'=>'definition'. I wanted the PHP to output a h3 element with th...

Is the same file tokenized every time I include it?

This question is about the PHP parsing engine. When I include a file multiple times in a single runtime, does PHP tokenize it every time or does it keep a cache and just run the compiled code on subsequent inclusions? EDIT: More details: I am not using an external caching mechanism and I am dealing with the same file being included mul...

Mysql: Getting Count of Comma Separated Values With Like

I decided to use favs (id's of users which marked that post as a favorite) as a comma separated list in a favs column which is also in messages table with sender,url,content etc.. But when i try to count those rows with a quey like: select count(id) from messages where favs like '%userid%' of course it gives wrong results because al...

UTF-8 characters that aren't XSS vulnerabilities

I'm looking at encoding strings to prevent XSS attacks. Right now we want to use a whitelist approach, where any characters outside of that whitelist will get encoded. Right now, we're taking things like '(' and outputting '&#40;' instead. As far as we can tell, this will prevent most XSS. The problem is that we've got a lot of internat...

Is PHPDoc verbosity more trouble than it's worth?

I tried using PHPDoc for the first time today and quickly ran into a problem. For every 1 line of variable declarations, I had at least 5 lines of comments. Example: /** * Holds path the remote server * @name ... * @global ... */ $myvar = ... Of course, the payoffs are nice - but this turns a 10-line config file into a 60-line ...

Problem setting PHP SESSION variables within cross-domain iframe

Coles Notes version: index.php?map_id=foo is loaded into iframe on www.not-my-domain.com. index sets SESSION['map_id'] = foo. Flash file tries to get SESSION['map_id'] thru Authenticate.php, but Authenticate.php has no values set for any SESSION varaibles. -- Only first-load, cross domain issue. Verbose: I have an index while where I...