Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - Chris

Pages: [1]
1
Beginners - Learning PHP / Is Precedural Enough?
« on: July 11, 2012, 12:28:10 AM »
A Note to Moderators: If you feel that my question below does not belong in this section, please let me know where it should be posted.

Thanks,
Chirs



Hello,

Without any programming experience whatsoever, I started studying PHP beginning in the second quarter of this year with the goal of slowly building my dream website starting later this summer.

Just as I was wrapping my head around PHP and beginning--I felt-- to truly understand the different concepts and how the code works (this is why I prefaced my post with my non-experience--I've really had to bang and cram it all in my head), I come across Object Oriented PHP.

I've taken the approach of of mastering (trying, as much as possible, at least) as many of the concepts and ideas before diving in to try and create my own scripts; much like learning how to dribble, throw a baseball or football well, before playing a single game. (of course I've played around with and done some code -drills).

My question to the experts is this: Should or must I learn and delve deep
into OOPHP, thus delaying my "start-to-code" date? Or will procedural PHP Programming suffice if one would like to build good E-commerce, forum/comment-type (like PHP Help) or basic social networking websites?

How far will procedural programming take me? A site with 1,000; tens-of-thousands; hundred thousand visitors?

Your expert opinion and insight and input is greatly appreciated.

Chris

2
Beginners - Learning PHP / Understanding "Formula" Code
« on: July 10, 2012, 10:35:43 AM »
Hello,

Came across this piece of code for a Factorial "formula" and can't seem to get it:

PHP Code: [Select]
<html>
    <
head>
        <
title>Factorial Test</title>
    </
head>
    <
body>
        <?
php
            $var 
rand 10;
            
            
$counter $var;
            
            
$echo_var $var;
            
            while (
$counter 1) {
                
$var $var * ($counter 1);
                
                
$counter--;
            }
            
            echo 
"The Factorial of $echo_var is: $var";
        
?>
    </body>
</html>


Could an expert kindly explain how the code works (step by step, if possible).

Thanks in advance.
Chris

3
Beginners - Learning PHP / Empty array
« on: July 06, 2012, 06:54:54 PM »
Hello,

Need some help understanding array().

I'm confused about an empty array. How does it work?

I found this example (about shopping carts):

PHP Code: [Select]
$_SESSION['cart'] = array();
$_SESSION['cart'][1] = 10;
$_SESSION['cart'][6] = 5;


Again, what does the array() mean? Aren't you supposed to put  values in arrays?

Thanks in advance.

4
Beginners - Learning PHP / $row[0]
« on: May 24, 2012, 06:56:14 PM »
Hello,

I know this may sound like a stupid question, but I just want to make sure I understand correctly.

After a query, what does $row[0] stand for/ result in?

Is my understanding correct that $row[0] shows ALL results?

HERE ARE EXAMPLES:

PHP Code: [Select]
$query "SELECT count(commentid) from comments where jokeid = $jokeid";

$result mysql_query($query);

$row=mysql_fetch_array($result);

if (
$row[0] == 0)

{

   echo 
"No comments posted yet.&nbsp;&nbsp;\n";

  

} else

{

   echo 
$row[0] . "\n";
   echo 
"&nbsp;comments posted.&nbsp;&nbsp;\n";



AND THIS ONE

PHP Code: [Select]
$query "Select count(prodid) from products where catid = $catid";
      
$result mysql_query($query);
      
$row mysql_fetch_array($result);
      if (
$row[0] == 0)
      {
         echo 
"<h2><br>Sorry, there are no products in this category</h2>\n";
      }
      else
      {
         
$totrecords $row[0];


Thanks in advance,
Chris

5
Beginners - Learning PHP / ob_?
« on: May 18, 2012, 02:17:05 PM »
Hello,

I'm on my seventh week of learning PHP (no previous coding experience) and came upon this code:

PHP Code: [Select]
         //create thumbnail
         
$width imageSX($SourceImage);
         
$height imageSY($SourceImage);
         
$newThumb imagecreatetruecolor(8060);
         
//resize image to 80 x 60
         
$result imagecopyresampled($newThumb$SourceImage
                                      
0000,
                                      
8060$width$height);
         
//move image to variable
         
ob_start();
         
imageJPEG($newThumb);
         
$thumbnail ob_get_contents();
         
ob_end_clean();



QUESTION:
What exactly is ob_start() in plain english; along with it ob_get_contents() and ob_end_clean()? --In general and what it does for the specific code example above (I get the manipulating image part of the code).
How does buffering work?

Thanks in advance,
Chris

6
Beginners - Learning PHP / Forms Processing--PHP/HTML
« on: May 02, 2012, 05:57:55 PM »
Hello,

I'm learning and trying to understand how html forms and php processing works.

Came across this pair of examples:

HTML FORM:
PHP Code: [Select]
<html>
<
body>

  <
form action="hello-web.php" method="GET">
  <
label>Name:</label>
  <
input type="text" name="yourName" size="24">
  <
input type="submit">
  </
form>

</
body>
</
html>



PHP PROCESSOR:
PHP Code: [Select]
?php
$fname 
$_GET["yourName"];

echo 
"Hello $fname!";
?>


OUTPUT SHOULD BE:
Hello Entered/Example Name!


QUESTIONS:
When I play around with the code and try to change the variable "yourName" (on BOTH HTML and PHP files) to, for example "typeName" , the entered name on the form does not show up/ not processed.

In other words, the output becomes just: Hello  !

Is yourName a standard php or html variable? Can it not be changed to what ever you want it to be?

Better yet, how exactly does the form process data?

Thanks in advance,
Chris

7
Beginners - Learning PHP / Back Slashes
« on: April 12, 2012, 05:03:52 PM »
Hello,

Still learning PHP and came across these examples:

PHP Code: [Select]
echo "<a href=\"index.php?content=register\">Try again</a><br>;

echo "
<a href=\"index.php\">Return to Home</a>;


AND

PHP Code: [Select]
echo "<input name=\"goButton\" type=\"submit\" value=\"browse\" />;
echo "
<input name=\"content\" type=\"hidden\" value=\"edit\" />;


My question is: What purpose or function do all the back slashes serve?
Can't it be just :
PHP Code: [Select]
echo "<input name="goButton" type="submit" value="browse"
 --without all the backslashes?

Thanks in advance.
-Chris


8
Beginners - Learning PHP / $_REQUEST
« on: February 03, 2012, 07:24:13 PM »
Hello,

Does: $_REQUEST['______'] have the same basic function as $_POST['______'] and or $_GET['______'] ?

If not, what does $_REQUEST specifically do?

If all three listed above are basically the same, what are the differences?

I've been searching $_REQUEST but can't seem to find threads that expound on it.

Thanks in advance.
Chris

9
Beginners - Learning PHP / Range (incerementor?)
« on: January 27, 2012, 02:12:50 PM »
Hello,

I accidentally discovered this while playing around with "RANGE".

PHP Code: [Select]
<?php
$numbers 
range (1,202);
   
sort($numbers);
      for(
$n=0$n<=20$n++) 
     {
        echo 
"$numbers[$n]<br \>\n";
     {
?>


OUTPUT:
1
3
5
7
9
11
13
15
17
19

Whoa! Is this a standard function of "range"--the last digit /element in the "range" acts as an incrementor?
Any other neat functions with regard to this?
Or is this a fluke?

Thanks,
Chris


10
Hello,

First of all, I'd just like to say that this forum is awesome! I'm a total programming newbie asking questions which have been sufficiently explained.

As I'm learning,  really want to know the nuances of how the codes "operate", not just settling for "that's just the way it works".

In that regard, I have this questions about assigning a variable to another variable (did I define that right?). I believe it is called REFERENCING?

PHP Code: [Select]
<?php
$firstVar 
'nice day!';           
$secondVar = &$firstVar;            
$secondVar "Have a  $secondVar";  
echo 
$firstVar;
echo 
$secondVar;  
?>


...which outputs: Have a nice day! Have a nice day!

I sort of get the idea that the $firstVar is referenced via $secondVar.

What's really confusing to me is the echos. It's like the code is reading and echoing backwards from the last $secondVar to the middle and then $firstVar.

Shouldn't the first echo $firstvar output "nice day! Have a" ? Obviously it is not, so I'd like to know how the code "thinks".

Thanks in advance.
Chris

11
Beginners - Learning PHP / Two Dimensional Arrays
« on: January 17, 2012, 02:38:24 PM »
Hello,

I'd like to learn how the following code for two dimensional arrays works:

PHP Code: [Select]
<html>
<
head>
<
title>For loop test </title>
</
head>
<
body>

 <?
php
// Declare two-dimensional array
    
$matrix  = array (array (1,2,3),
            array (
4,5,6),
            array (
7,8,9)
                    );
                
                echo 
"<h3>"."This is two dimensional array"."</h3>"."</br>";
// Print two dimensional array element
    
for($row $row <$row++)
    {
    for(
$col ;$col <;  $col++)
        {
                echo 
$matrix[$row][$col]."\t"."\t";
        }
                echo 
"</br>";
        }

?>

</body>
</html>



How does the code determine which is $row and $col when it was not assigned or mentioned earlier in the code> Are $row for ROW and $col for COLUMNS standard php variables?

If you have a better way of explaining this other than my train of thought (also how it relates to FOR loop) please do so.

Thanks,
Chris

Pages: [1]