php

mySQL Table Structure for a User-based website.

I am developing a website that has user profiles, accounts, account settings, inboxes, etc. just like Facebook or LinkedIn and I'm wondering how to set up the mySQL tables for it. Should I create a table for every user for each function (profile, inbox, etc.)? ...

What is the "Starting Point" For PHP's set_include_path

What is set_include_path Relative to, in PHP? Is it the folder where the PHP.exe resides? Is it the webroot? In other words, what folder would set_include_path('/') or set_include_path('.') be referring to? ...

Top X-posts of the past week? SQL/PHP [figured it out]

How can I get the top X posts of the past week? I have two tables: td_table - holds info about the post; vote_table - holds the info about the votes that have been made for the posts. The following gives me the top three posts (those that have most votes for), but it gives me the top three of all times. $query = 'SELECT t.id, t.content,...

Load ajaxdata in HTML or JSON-format?

What's a better practice? Load data in HTMLformat or JSON-format? When I load HTML i'm able to keep all the html in my php view-file. When i load JSON I have to put it in html elements clientside with javascript. I know that a 'best-practice-question' isn't suitable for stackoverflow. So a better answer to my question is a list of benef...

Determine What Line a Function Was Executed From

I'm trying to build an error class and a lot of error classes I've looked at in the past use FILE and LINE to show where the error occurred, but they use them in the function so they're always the same, which is highly useless information. Aside from sending an array of containing FILE and LINE with every function (which would get to be ...

PHP how to assign class property variables conditionally

Hi, I'm new to php classes, arrays, etc, so pls excuse me if I don't use the correct terminology. What I'm looking for is how to assign easily values to properties from a class without having to depend on "if" statements. For example: Suppose I have an instance of a class test, and "test" has a property "employee" (hope this is the co...

PHP PEAR Validate Package - Fatal error: Class 'Validate' not found

This is the error I am receiving: Fatal error: Class 'Validate' not found in C:\xampp\htdocs\final_project\validate.php on line 5 And here is my PHP code: <?php require_once 'Validate.php'; foreach($_POST as $name => $value) { $valid = Validate::string($value); } ?> I do not understand what I am missing. I installed --alldep...

objects throwing exceptions inside of objects

I'm working on an object that at some point instantiates another object. That inner object might throw an exception. I could just let that exception bubble up to whatever code is handling the parent object, which is what I want to do, following the philosophy of KISS. Or, I could do some exception handling within the parent object, and p...

how can I deliver remote content via web service?

We have multiple websites under different domains that need to receive our banner ads. We have a server app, in PHP, that returns the HTML for a randomly-generated banner ad. Out of concern for the client side, I don't want to use an iframe nor do I want to include the jquery library because of the weight - I also do not want to duplica...

PHP rounding problem (5.2.3)?

I'm wondering if I found an issue with the rounding in PHP, specifically 5.2.3 (I'm not sure about other versions at the moment): $t = 0; $taxAmount = (5.000 / 100) * 0.7; $t += $taxAmount; var_dump($t); // float(0.035) var_dump(round($t, 2)); // float(0.03) var_dump(number_format($t, 2)); // string(4) "0.03" To me 0.035 should roun...

Using PHP/Apache to restrict access to static files (html, css, img, etc)

Lets say you have lots of html, css, js, img and etc files within a directory on your server. Normally, any user in internet-land could access those files by simply typing in the full URL like so: http://example.com/static-files/sub/index.html Now, what if you only want authorized users to be able to load those files? For this example, ...

assign a class of current to the current page in the navigation when all headers are included via <?php include()?>

I have all the headers and the top navigation included in the page with PHP I want to assign a class to the <li class="current"> so i have a list of <li>'s and the current page should get a class of "current" and the body should get a class of the current page for http://www.mysite.com/home = the body should be <body class"home"> ...

Facebook's HipHop - What's it for?

The news in the PHP world today is Facebook's HipHop, which: HipHop for PHP isn't technically a compiler itself. Rather it is a source code transformer. HipHop programmatically transforms your PHP source code into highly optimized C++ and then uses g++ to compile it. HipHop executes the source code in a semantically equivalent manner...

Reusing MySQL results

Hi there, I'm having somewhat theoretical question: I'm designing my own CMS/app-framework (as many PHP programmers on various levels did before... and always will) to either make production-ready solution or develop various modules/plugins that I'll use later. Anyway, I'm thinking on gathering SQL connections from whole app and then ...

How do I use Ajax and Jquery to pull information off a PHP database, and populate elements with that information?

Hey everyone, I am tweaking a website to make it easier for employees to edit products. Right now, someone has to login to the DB and change prices, and then someone has to change the physical html of the website itself. So I am writing code that pulls all the products off the DB, and displays them on a page which can be edited. I thi...

UTF-8 characters in preg_match_all (PHP)

I have preg_match_all('/[aäeëioöuáéíóú]/u', $in, $out, PREG_OFFSET_CAPTURE); If $in = 'hëllo' $out is: array(1) { [0]=> array(2) { [0]=> array(2) { [0]=> string(2) "ë" [1]=> int(1) } [1]=> array(2) { [0]=> string(1) "o" [1]=> int(5) } } } The position of o should be 4. I've read about this problem on...

Can I get all keys of an multi level associative arrays in php

Is there any way in php wherein I can get n level keys for multi-dimensional array in php ? Here is my associative array and as output I want an array which would contain all the values for keys object_id as you can there from the structure itself there are many nested levels for object_id and so how can I get all the values for keys ob...

JQuery UI Nested Tabs - Load AJAX content into a single DIV

All, I am using JQuery UI Nested tabs. Consider the structure like this: There are 2 Main tabs: Animals, Birds. Under Animals, there are two tabs "Cats", "Dogs". Both the tabs "Cats" and "Dogs" should be loaded via AJAX when clicked.. So, the code for them is something like this: <div id="fragment-1"> <ul> <li><a href="/publ...

Mysql_fetch_assoc(): supplied argument is not a valid MySQL result …

I tried everything I could think of, but I keep on getting this error. Mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /url/ on line 41 if ( $_POST[submit] == "Submit" ) { $sql="INSERT INTO table (`content`, `userid`, `ttime`) VALUES ('$_POST[content]', '".$user_id."', '".time()."')"; $r...

Displaying number of results from a MySQL db...

I have a classifieds website, and it is using MySQL as a database. My goal is to show the number of private, company and total ads in the db with the search-term entered in a text-input inside the form! The Problem: There are two types of ads: Private, and Company. The user may specify which to display, or both, so thats three options....