Help - Search - Member List - Calendar
Full Version: Knowledge of PHP
Krazy Letter Forums > Technology > Tech Help > Programming Help > PHP
clunky
Oh well, all this Object Oriented stuff dosent click for me, but my scripts are killer fast! clap.gif
lappy512
I know how to make sessions, mysql interface, regular expressions,etc, and 1/2 OOP. I have yet to use it much, but I can use it, but not all advanced stuff. And I can't do fancy schamey stuff. biggrin.gif
Mynck
I know that echo prints stuff to the HTML and i know while loops
I know how to use arrays, advanced conditionals
But what do you mean by "advanced conditionals?"
I know how to make mysql interface
I can do OOp


OOP is easy tongue.gif
Probably because the first programming language I learned was completely OOP
Ali
I know just about enough.
I know what echo does, and what print does. I know about variables and using php with mysql (add, edit, and delete rows, create table, call up mysql info from mysql with php).
I don't know how to use loops (those confuse me).
And sessions, haven't gotten around to learning that yet.
Mynck
While loops are pretty easy.

while (conditional) {
body;
}

What that does is that when it gets to there, it checks to see if conditional is true. If it is, it runs the body, then repeats from the start, checking the conditional again. If the conditional is false, then the loop ends and it goes on to the next line.


-----Edit-----

And I might as well get to for loops too.

for (initialization; conditional; increment) {
body;
}

This is pretty much the same as

initialization;
while (conditional) {
body;
increment;
}

Initialization usually sets up a variable. Then the conditional will check the variable's value. Then the increment will change the variable's value.
lappy512
added a PHP tag. You can see it right after the code button
PHP
<?php
    
function unparse_php_tag($txt="")
    {
        global 
$ibforums;

        
$txt str_replace("<!--SDS-->$<!--EDS-->""$"$txt);
        
$txt str_replace("<code>" ""  $txt);
        
$txt str_replace("</code>"""  $txt);
        
$txt str_replace("</font>"""  $txt);
        
$txt str_replace("</span>"""  $txt);
        
$txt preg_replace("#\<font(.+?)>#"""$txt);
        
$txt preg_replace("#\<span(.+?)>#"""$txt);
        
$txt preg_replace("#^<span(.+?)><br />(.+?)#""\\2"$txt);
        
$txt preg_replace("#(.+?)(?:<br />){1,}$#""\\1"$txt);
        
$txt str_replace("<br />" "\n"$txt);
    }
?>

Took out the return statement, since it contained the php tag, and messed things up.
Ali
Thanks, been wondering about those for a bit.
The only stuff I use is really just echo, print, variables, and anything that has to do with mysql control in php.

PHP
<?
// Just testing out the php tags. =P
$flamingo 1;
$willy_wonka "the amazing choclateer";
$agustus "tubular";
$veruka "squirrels";
$violet "techno";
$mike "teleport";
$pacman "teh suck";

// You can tell I watched "Charlie and the Chocolate Factory" recently XD
?>
djbob
I know the OOP stuff. Although I'm a little worse with it on PHP5 then on PHP4.
lappy512
QUOTE(Ali @ Jan 5 2006, 12:00 AM)
Thanks, been wondering about those for a bit.
The only stuff I use is really just echo, print, variables, and anything that has to do with mysql control in php.
*


What's that "alipanel" you are coding?

Woah, just went to your website...changed for the first time in 1000 years biggrin.gif
clunky
By advanced conditionals I mean switch statements and, um well... If, elseif, else i guess? I dont really know
lappy512
foreach is a useful loop... smile.gif
Mynck
QUOTE(clunky @ Jan 9 2006, 10:11 PM)
By advanced conditionals I mean switch statements and, um well... If, elseif, else i guess? I dont really know
*



Those are advanced...?
What about the ? : thing?

I think Java has a special foreach thing too. But it only works with Iterators. And it's still called a for loop. Just has a different format.
The Admiral
I made a temperature converter...granted I was using a guidebook...but I have little use for PHP.
Mynck
QUOTE(The Admiral @ Jan 9 2006, 10:41 PM)
I made a temperature converter...granted I was using a guidebook...but I have little use for PHP.
*


That could more easily be done with Javascript.
clunky
Or TI Basic biggrin.gif
Ali
QUOTE(lappy512 @ Jan 5 2006, 10:30 PM)
What's that "alipanel" you are coding?

Woah, just went to your website...changed for the first time in 1000 years biggrin.gif
*

lmao, with World of Warcraft and IRC and all the other junk I do, I don't have much time for my site. I'm tempted just to use phpnuke instead of coding my own site, but what holds me back is the memory of how weird the phpnuke system is. I'll get to coding it again in the summer. I'll be going to a tech came for about a week (maybe more), so that will cut a bit of time out of my site.

aliPanel will be the cms I'll use for my site. I first intended it to be something I'd sell to little 7th graders (all of them are midgets! D=) who want to make a website. They'd have their website and I'd have money. Now I decided just to make it for my site only. I'd make money by teaching students web design stuff and fixing websites for them and related stuff. I charge S$10-S$20 for 1 lunch break of tutorial, and $10 for a web site fixing.
lappy512
Yeah, making the upgrader and installer and the User-Friendly parts are the hardest (from my experience in PHPKImageHost)
clunky
This is an example from the mailscript admin page
http://www.dubemail.com/mail/admin.php

Note the while loop to go trhough each row from the SELECT query. Thats one of the mysteries of php, using a while loop for that.

Also, a foreaach wouldnt work in for each cell in the row, becuse what if a cell was empty? there would be a misalignment.

PHP
<?php
echo "<h1>BIG BROTHER IS WATCHING - The administration/log page</h1>";

echo 
"<h3>Stats</h3>";
$num_rows mysql_num_rows(mysql_query('SELECT * FROM EmailSent'));  #SOME STATISTICS USING SQL's MATH
$tot_email mysql_fetch_array(mysql_query('SELECT SUM(`runs`) FROM EmailSent');
$avg_send_per_use mysql_fetch_array(mysql_query('SELECT AVG( `runs` ) FROM `EmailSent`'));
$distinct_ip mysql_fetch_array(mysql_query('SELECT COUNT(DISTINCT(`ip`)) FROM EmailSent'));

echo 
"
<ul>
  <li>The script has ben used <strong>$num_rows</strong> times. </li>
  <li> A total of <strong>$tot_email[0]</strong> emails have been sent. (This is the sum of the number of sends.)</li>
  <li>For every use of the script, an average of <strong>$avg_send_per_use[0]</strong> sends have been made.</li>
  <li> There have been sends by <strong>$distinct_ip[0]</strong> different (distinct) IP addresses. </li>
</ul>"
;

#ALL THE DATA
#The header row for the table
echo '
<table width="95%" border="1">
<tr>
    <th scope="col">id</th>
    <th scope="col">ip</th>
    <th scope="col">browser</th>
    <th scope="col">datetime</th>
    <th scope="col">to_prefix</th>
    <th scope="col">to_dom</th>
    <th scope="col">fr_prefix</th>
    <th scope="col">fr_dom</th>
    <th scope="col">subject</th>
    <th scope="col">runs</th>
    <th scope="col">message</th>
</tr>'
;
#does the while loop for each row
$i 1;
while (
$i <= $num_rows)
    {
    
$data mysql_fetch_row(mysql_query("SELECT * FROM EmailSent WHERE `id` = '$i'"));
    
#echoes out the array into each column (in each row)
    
echo "
<tr>
    <td>$data[0]</td>
    <td>$data[1]</td>
    <td>$data[2]</td>
    <td>$data[3]</td>
    <td>$data[4]</td>
    <td>$data[5]</td>
    <td>$data[6]</td>
    <td>$data[7]</td>
    <td>$data[8]</td>
    <td>$data[9]</td>
    <td>$data[10]</td>
</tr>
        "
;
    
    
$i++;
    }

/* 
$i = 1;
while ($i <= $num_rows)
    {
    $query = mysql_query("SELECT * FROM EmailSent WHERE `id` = '$i'");
    $data = mysql_fetch_row($query);
    #echoes out the array into each column (in each row) */

mysql_close($connection);
echo 
'</table>';
echo 
'<br>Done!';
?>

Mynck
QUOTE(clunky @ Jan 10 2006, 09:20 PM)
Note the while loop to go trhough each row from the SELECT query.  Thats one of the mysteries of php, using a while loop for that. 
*



Wouldn't a for loop work better for that?
PHP
for ($i = $num_rows - 1; $i != 0; $i--)
{
$blah-->doSomething();
}

The reason why I made it start out high and then decrease is because comparing to 0 is very fast.
clunky
I suppose a for loop is faster, but how many microseconds differnece does it make when the server is comparing 100 to zero as apposed to 0 to 0?
lappy512
Even better:

PHP
<?php
//assume mysql is already connected, database is already selected, etc...

$queryresult mysql_query('SELECT * FROM EmailSent ORDER BY 'id' ASC')

while(
$row mysql_fetch_array($queryresult))
{
    echo 
"Name: $row['name'] IP: $row['ip']";  //etc etc. 

?>



mysql_fetch_array returns false if there are no more db records to get.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.