PDA

View Full Version : Getting advanced with PHP


deLive
04-13-2005, 06:18 PM
I've been working with php/mysql/javascript/html etc for about 1.5 years now and it seems like I'm stuck. I want to put in advanced features to the websites I create but can't seem to get a handle on some of the more complicated php functions. One example is creating a search function that

http://iamcal.com/publish/articles/php/search/

The code for that just is mind boggling for me yet it seems like a simple function I just cannot do. It seems like I don't have a clear enough understanding on array's for that specific function but there are many more things I would like to learn. I can make control panels to do easy things such as manage website content but nothing special. I would like to be more advanced and perhaps go into ecommerse, or create a website that scheduals tournments. Also, I have been asked on multiple occasions to integrate some other type of php, or some other persons php code. I look at the coding and it looks very VERY different in structure and other things then my coding. I suppose that I am just an intermediate coder who still uses basic thought processes? Anyways, If you have any ideas or websites or perhaps even other people's code that I could look at and proceed to be a better programmer then I am currentely and get into a company to create control panels for them I would appriciate it. Thanks

Mr. Popularity
04-13-2005, 09:07 PM
well, start with the basic advanced stuff like arrays, parse_ini_file, simple database connections and queries, sorting and that kinda stuff... read through the functions on the php docs and things will come together for you in NO time!

deLive
04-13-2005, 09:19 PM
thanks for the info. I am able to grab specific information though databases etc. That I actually do know how to do. The sorting part is something I really have not done at all. Obviously its important I just seem to never have hit on it all that much. Also, do you know of any free control panels online that I can just look at the interface to see what theirs looks like compared to mine. Thanks for the input, more comments would be appriciated :)

Mr. Popularity
04-14-2005, 01:47 AM
SELECT * from databasename SORTBY fieldname ASC

iDxMan
04-14-2005, 09:45 AM
SELECT * from databasename SORTBY fieldname ASC

ORDERBY fieldname ASC


deLive: Some of the searching will [obviously] depend on your data. What does the data look like?

-r

deLive
04-14-2005, 04:49 PM
Ah, well this wasn't specific to any type of data, just in general. I was curious about data manipulation. Such things as taking a string of data and dividing it into an array where each element was one character of the string. Then using array functions to remove spaces replace < with the html value etc. Is there a place that I can find good demonstrations of these commands being used other then php.net where most of the examples are way over my head?

iDxMan
04-15-2005, 09:39 AM
Yeah, some of those user comments get a bit advanced at times, but some basic array stuff shouldn't be too bad.

As far as removing spaces there are a number of options.

- preg_replace - probably a bit on the advanced side, but powerful
- str_replace - easy function to do string replacement
- htmlentities - :) built-in function to convert chars into their html equivalent

Although something like the following is probably close to your array question: (I didn't check it, but it should work)


$str = 'abcdefg hijklmn o p';
$ar = Array();

$ar = explode('', $str);

foreach ($ar as $k => $v) {
if ($v) {
$ar[$k] = trim($v);
}
else {
unset($ar[$k]);
}
}

sort($ar);
reset($ar);

$str2 = implode($ar);

deLive
04-15-2005, 06:17 PM
Thanks for the reply, the bit of code does defentely clear some things up. It also reminded me of a piece of a code a friend showed me that I never quite understood how it worked but somewhat understand what it does. If you or anyone else could go through it line by line and explain it in more detail that would be great.


$query = "SELECT `key`, `dim`, `value` FROM order_vars WHERE `id`>'0'";
$result = mysql_query($query);
while($rs = mysql_fetch_array($result, MYSQL_ASSOC)) {
if (isset($rs[dim]) && $rs[dim] != "") {
${$rs[key]}[$rs[dim]] = $rs[value];
} else {
${$rs[key]} = $rs[value];
}
}