ShawnCplus 456 Code Monkey Team Colleague

Na I doubt an interview question, prolly homework would be my best bet.
When you do explain could you also explain what is 3 tier architecture and its relation to frameworks in php? Thanks

3 tier = grand parent, parent, child?

Back to school for me it seems :D HA

He's probably mistaken the term '3 tier' to mean MVC or Model, View and Controller. A lot of PHP frameworks (most) are based off of this design philosophy. In an MVC Framework the Model (the database in this case) acts separately of the View (any html output), and the Controller (any business logic) which controls it all. The main reason for this is so you don't have a bunch of database queries and PHP code in your template files.

ShawnCplus 456 Code Monkey Team Colleague

Usually when you have bold/italic text there will be separate ttf files for the standard font, the bold font and the italic font so just load those as separate fonts and write text using them.

ShawnCplus 456 Code Monkey Team Colleague

When you draw text you have to tell the function the x and y positions. Build an array of strings by exploding on newlines then iterate over the array and modify the Y value based on the bounding box of the previous (see http://us3.php.net/manual/en/ref.image.php)

ShawnCplus 456 Code Monkey Team Colleague

If its an interview question then I'll make sure I've waited a day or so to answer you. Lying about things you don't know will not get you a job.

ShawnCplus 456 Code Monkey Team Colleague

what is this dasasadadadadda stuff? Are you just trying to bump your post with no meaningful information, or ask a question? I told you in my first post, you don't have a mysql server started on localhost, so start one or point to one.

ShawnCplus 456 Code Monkey Team Colleague

Sure, why not. (If you're looking for us to give you the code that's not going to happen)

ShawnCplus 456 Code Monkey Team Colleague

well php is a serverside language and extjs is Javascript (clientside) so unless you're using a framework there really is no integration between the two

ShawnCplus 456 Code Monkey Team Colleague

Ok, I see. I really never dealt with anything like that.

I did notice that the code doesn't like self-closing tags. So you might want to look into that.

I will think about how to simplify and clean up the code.

Good call, the code should allow for it but I haven't added the case to my unit tests though.

ShawnCplus 456 Code Monkey Team Colleague

I would have to better understand how its used, like in what type of application, before I can help clean it up. I personally can't think of any reason for it.

As I said it's a tokenizer so it takes in html

<html><head>
  <title>Text</title>
</head>
<body>
  <span class="test">blah</span>
</body>
</html>

and produces this

array (
  array (
    T_TAG_START
    <
  )
  array (
    T_TAG_NAME
    html
  )
  array (
    T_TAG_END
    >
  )
  ...
)

The syntax highlighter takes this token array, and a processed token/color map to produce highlighted text (in this case it is only for the command line using ECMA48 SGR sequences for color)

Also, as I said, there's nothing really wrong with it error-wise, it just needs a little cleanup and probably some optimization.

ShawnCplus 456 Code Monkey Team Colleague

Your mysql_connect call isn't in that code but I can tell that you don't have a mysql server setup on localhost.

ShawnCplus 456 Code Monkey Team Colleague

use cURL, the documentation on php.net is pretty good

ShawnCplus 456 Code Monkey Team Colleague

so my understanding is i would just have to use preg_replace and escape the character i have in the string

$sometext = preg_replace('\{name\}', '<?php echo $myrow[\'name\']; ?>', $sometext);

cause i do not understand this

/\s*\{(\w+?)\}\s*/i

/\s*\{(\w+?)\}\s*/i says anything that is { then the letters a-z or underscore then } so {name} or {state}, etc. and replaces it with whatever was between the {} so {state} would become <?php echo $myrow['state']; ?> and {name} would be come <?php echo $myrow['name']; ?> The way you're doing it is pointless to use preg_replace because its not a regular expression, its just a string and you could use str_replace

ShawnCplus 456 Code Monkey Team Colleague

I wrote this FSM to tokenize HTML for my syntax highlighter, it works pretty well and its fast but its currently ugly as all heck and could definitely use some love so if anyone is up for taking a whack at cleaning it up or giving me some speed hints it would be much appreciated.

Warning: Big Code Block

<?php
/**
 * Simple FSM for tokenizing HTML, there are probably more accurate,
 * better written tokenizers out there but I didn't feel like searching
 * so I wrote this, it's fast enough for me.
 *
 * @author Shawn Biddle (email redacted)
 * @version 0.5
 */

define('T_TEXT', 0);
define('T_TAG_START', 1);
define('T_TAG_NAME', 2);
define('T_TAG_END', 3);
define('T_STRING_START', 4);
define('T_STRING_END', 5);
define('T_TAG_END_NAME', 6);
define('T_END_SLASH', 7);
define('T_HTML_COMMENT', 8);

/*
  There is currently no state table built for this so it's quite ugly,
  feel free to clean it up later
*/

function tokenize_html($output)
{
  $states = array('T_TEXT', 'T_TAG_START', 'T_TAG_NAME', 'T_TAG_END', 'T_STRING_STRING', 'T_STRING_END',
    'T_TAG_END_NAME', 'T_END_SLASH', 'T_HTML_COMMENT');

  $i = 0;
  $ret_tokens = array();
  $state = NULL;
  $char = '';
  $prev_char = '';
  $cur_state_string = '';
  $delimiter = '';
  /*
   This isn't while($char = $output[$i]) because if it comes across a 0 in the text
   it will die because of the implicit cast string -> int -> boolean
  */
  while(isset($output[$i])) {
    $char = $output[$i++];
    switch(TRUE) {
      case (preg_match('/[^\<\>\/\'"]/ism', $char)):
      {
        if ($state === NULL || $state == T_STRING_END || $state == T_TAG_END) {
          $state = T_TEXT;
          $cur_state_string = $char;
          break;
        }

        if ($state == T_TAG_NAME && $char == …
ShawnCplus 456 Code Monkey Team Colleague

is it possible to do some kind of str_replace and replace the thing with a php string.
ex:

{name}

to

<? myrow['name']; ?>

Well it sounds like you're trying to write a template parser in which case I'd recommend using a prebuilt one like Smarty or just searching for PHP template parser. However, if you want to go at it alone you can use regular expressions.

$sometext = preg_replace('/\s*\{(\w+?)\}\s*/i', '<?php echo $myrow[\'\1\']; ?>', $sometext);
ShawnCplus 456 Code Monkey Team Colleague

I have no idea what you're trying to do, you're already are passing those variables to the function.

buildString(this, data.cells[i].letter, x, y);
ShawnCplus 456 Code Monkey Team Colleague

im not thinking at all.... all i can do is say

cout << num << "00";

or is there a way to multiply with <<??

haha, that's thinking outside the box. Yeah, that'll work for "multiplying" by 100 but if you want to change the multiplier to 5 then you're boned. This made me laugh pretty hard.

ShawnCplus 456 Code Monkey Team Colleague

OK, lets get one thing clear: AJAX involves sending requests to another server and processing the response. DHTML involves manipulating the DOM. Fancy effects are NOT AJAX, they are DHTML. And to achieve the same effects as Flash in HTML you really have no other choice but to use a <canvas> tag which is in HTML5 and not supported by all browsers.

ShawnCplus 456 Code Monkey Team Colleague
window.location.pathname

returns the string after the hostname. window.location is an object. If you're using firebug just type window.location in the console window and click on the output and you can see all of the properties you can access.

ShawnCplus 456 Code Monkey Team Colleague

In the way you're creating the variable, no. You can't do that in any language that does object orientation (or at least you shouldn't.) It wouldn't make any sense for Father to inherit the traits of Son. If you want to have a class that uses the traits of Son have it extend the Son class.

ShawnCplus 456 Code Monkey Team Colleague

You're missing an ending parenthesis on almost all of those conditions. You don't need to disambiguate so much.

if ( (strlen($Type) > 0) && (strlen($Brand) > 0  ) && (strlen($Size) > 0  ) && (strlen($Price) > 0 ) )

can just be

if ( strlen($Type) > 0 && strlen($Brand) > 0 && strlen($Size) > 0 && strlen($Price) > 0 )
ShawnCplus 456 Code Monkey Team Colleague

Hi, he is my post, i would like you to : try it yourself first
thank you very much

ShawnCplus 456 Code Monkey Team Colleague

Well you could do it either in PHP and Javascript or just Javascript. In PHP you would use $_SERVER['REQUEST_URI'] to get the request URI (who'd a thunk it?) and then give that to javascript to "paste" into the textbox. In purely Javascript you could use window.location.href as the value to put into the textbox.

ShawnCplus 456 Code Monkey Team Colleague

In members.php

// this will never do anything, you're never defining $UserName
if isset($UserName) {echo $UserName; }

// This does not do what you think it does
If (isset($_POST['UserName']))

//Connect to DB and Get the mailing list
$dbcnx = mysql_connect('myhost', '', '');
// This is what it actually does
If (isset($_POST['UserName'])) {
  //Connect to DB and Get the mailing list
  $dbcnx = mysql_connect('myhost', '', '');
}
ShawnCplus 456 Code Monkey Team Colleague

A) You fail for using marthastewart.com as a reference site and B) This should be in the javascript section.

ShawnCplus 456 Code Monkey Team Colleague

It's called PHP, go look at some tutorials. w3schools.com

ShawnCplus 456 Code Monkey Team Colleague

Hello I've a question when creating a class with functions.

e.g.

function constructor() {
	this.myFunc = function() {
		return "Hello World";
	}
}

do I have to write the function in that way? this.funcName = function() for every function in that class?

Because when I tried to write it in this way instead

function constructor() {
	function() myFunc{
		return "Hello World";
	}
}

It does not work if it is bundled like function in a function. When I create an object of constructor, and then try to call the myFunc function.

In Javascript functions are first class members meaning a function is a type just like an int or a string. Using this.varname = function(){}; is assigning a variable to this.varname, the variable type just happens to be a function. If you use function funcname(){} it declares it in the current scope and is destroyed once you leave that scope. IE., if you declare it inside another function you can't access it outside that function.

ShawnCplus 456 Code Monkey Team Colleague

Ok. Is that like this :

$query = "INSERT INTO tcg ClientsName, PrgNo, PrgName VALUES('$ClientsName','$PrgNo','$PrgName')";

??

Did you not read my post on how to do it? Go ahead, its about 4 inches above this post.

ShawnCplus 456 Code Monkey Team Colleague

How're you going to learn if you have everyone do it for you?

ShawnCplus 456 Code Monkey Team Colleague

No, the problem is that you aren't specifying the fields you want to insert into (this should be done even if you are doing them in order to save an internal lookup)

INSERT INTO <table> (field1, field2) VALUES ('field1_value', 'field2_value')
ShawnCplus 456 Code Monkey Team Colleague

Line 16 has echo, but lines 17 to 26 not. if php is in safe mode the error not appear, only show a blank page. May be this help.

This actually isn't an error, it just won't do anything. Those are completely valid statements (like I said, they just don't do anything)

ShawnCplus 456 Code Monkey Team Colleague

Why oh why did I even bother writing the FAQ that answers this very issue if no one is going to read it? It never stops baffling me when I see these posts.

ShawnCplus 456 Code Monkey Team Colleague

Requests (depending on the server) are usually handled in separate threads so my request to blah.php and your request to blah.php at the exact same time happen simultaneously*, in a non-blocking manner. If my request somehow fails, yours wont and vice versa. And unless something catastrophic happens and by some magical mystical force I corrupt memory that is the only way my data could overwrite yours (read wont happen).


*that's a whole other discussion I'm not going to get into here

Now, database queries are a wee bit different because they can be blocking (my query can block an incoming query), once again, depending on the server and in MySQL's case the database engine used. This is why transactions and the idea of atomicity are important. Note: MyISAM (The default engine of MySQL) does not support transactions. Also, InnoDB uses row-locking for reads/writes instead of table-locking. So if I'm doing a SELECT on a table with MyISAM the table will be unavailable until that SELECT is finished. Whereas with InnoDB it will act in sort of a cascade effect so as soon as I'm done reading a row it will become freed.

ShawnCplus 456 Code Monkey Team Colleague

That worked.

Thank you.

This kind of made me angry. Do you understand why xan's fix worked? Do you understand the operator precedence that is taking place between your statements? Are you aware of necessary disambiguation to avoid these issues? Or did you just accept it as "OK, now it works"?

ShawnCplus 456 Code Monkey Team Colleague

What is $today equal to?

ShawnCplus 456 Code Monkey Team Colleague

NOW() is a MySQL function

ShawnCplus 456 Code Monkey Team Colleague

If the account has IMAP enabled use that. http://lmgtfy.com/?q=php+imap

Will Gresham commented: Great site :) +2
ShawnCplus 456 Code Monkey Team Colleague
ShawnCplus 456 Code Monkey Team Colleague

I'd actually have to disagree with that one. There are a number of things wrong with it as noted in the comments, there are much better around the net.

ShawnCplus 456 Code Monkey Team Colleague
$day = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};

Is this even working? That is a syntax error, that's now how you declare arrays in PHP.

ShawnCplus 456 Code Monkey Team Colleague

Your function call itself shouldn't have the =array(1), only the definition should.

ShawnCplus 456 Code Monkey Team Colleague

Firstly, sqred isn't a property, its a class. Secondly, how else would you use an image without sending a request? (There are ways to do it by base64-encoding the image but it doesn't work in IE). If you're asking how to set the background-position of the list-style-image you can't. You could get around it by setting it to none and then manually putting a background image on each of the li's with a left padding

ShawnCplus 456 Code Monkey Team Colleague

As Ezzaral mentioned there is absolutely no need for you to build an entire website for this. Sites like Flickr and Picasa exist solely for this, use them, they're free.

ShawnCplus 456 Code Monkey Team Colleague

The files you require don't have to be in the htdocs folder, they can be anywhere on the filesystem. Only files that you want people to access should be in htdocs. So good practice is to put them in a semantically divided folder layout below htdocs, ie.,

/
  /webroot
    /htdocs
    /lib
      /db
        db.class.php
      /util
        processes.class.php
        other.class.php

Then you would just use an absolute path like /webroot/lib/db/db.class.php

ShawnCplus 456 Code Monkey Team Colleague

I have this attitude because you wont bother to help yourself. Your correct, this is a help forum, not a handholding forum.

ShawnCplus 456 Code Monkey Team Colleague

Go read up on how SQL works then come and ask the question again, I'm not going to help you until then. There are umpteen tutorials on the net, if you don't understand them its frankly not my problem and this is really simple stuff that you should be able to wrap your head around quite simply.

ShawnCplus 456 Code Monkey Team Colleague

Well if you want the activation key to be equal to something then put the variable in there like you did with $email

ShawnCplus 456 Code Monkey Team Colleague

Ahh, I didn't see that. Why do you have parenthesis around it, and why are you mixing saving the query to a variable then querying versus just querying?

AND is used instead of commas in the WHERE clause.

SELECT * FROM userinformation WHERE `email` = '$email' AND `username` = '' AND `activationkey` = ''
ShawnCplus 456 Code Monkey Team Colleague
$variable[]=$row[0];

Arrays use the []= operator, not +=

Venom Rush commented: A great help ;) +2
ShawnCplus 456 Code Monkey Team Colleague

No, you're not querying.

$query = ("SELECT * FROM userinformation WHERE `email` = '$email', `username` = ' ', `activationkey` = ' ' ");

should be

$query = mysql_query("SELECT * FROM userinformation WHERE `email` = '$email', `username` = ' ', `activationkey` = ' ' ");
ShawnCplus 456 Code Monkey Team Colleague

www.w3schools.com/jsref/jsref_obj_regexp.asp Regular expressions were made for this, they'll be hard to grasp at first but they'll be your friend in the end.

aashishn86 commented: thanks... +1