Jump to content

geno11x11

Member
  • Posts

    7
  • Joined

  • Last visited

geno11x11's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Thank you Ben, At very least, that tells me there is a rule that controls what I tried to do and explains why it would not work. My solution, in the interim, was to keep the declarations with the class and place the assignments within the function -- and that works. Is there an advantage using the __constructs method over my solution? It doesn't look any shorter, but I am working to update my coding technique to mysqli, the use of classes, etc. So if that would fall into the auspices of better coding, I will incorporate it as well.
  2. Four days, 28 views, and no replies... The obvious workaround is to break each statement into two - define the variable and follow it with the math expression assignment. But that nearly doubles the code, it is redundant, and it is inelegant IMO. Should I just chalk it up to a limitation to PHP and move on? This forum is about learning and improving our skills, right folks? Anyone?
  3. I am building an php include file. At the top, declared public and private variables contain both simple values and mathematical expressions. Those that include math within the declaration, such as $a=$b+$c, throw a syntax error. The strange thing is that php takes similar variable declarations in the calling file without complaint. There are many examples of mathematical expressions within variable declarations on the web, so it appears to be a legal practice. Whether I run the include file from the calling file or by directly accessing it in a browser, essentially the same error message occurs. Below I have included (1) the error message, (2) the entire include file, and (3) a portion of the main file that calls the include file. I would appreciate any thoughts or suggestions on this problem. Thanks for your help. (1) The error message: Parse error: syntax error, unexpected T_VARIABLE in /srv/www/htdocs/PNS/class.tablePagination.php on line 7 (2) Code from the include file generating the error: <?php class pagination { private $limit = 30; private $start = 0; private $eu = $start -0; private $space = " - "; $this1 = $eu - $limit; private $back = $eu - $limit; private $next = $eu + $limit; private $k = $j + $limit; public $beg; public $end; public function page() { private $eu = $start -0; $sql="select * FROM Complex"; /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $result = $db->query($sql); echo mysql_error(); $nume=mysqli_num_rows($result); // $nume is the total number of rows in the table. //echo 'Row numbers= ' . $nume; $p_limit=30; // Variables set for advance paging - should be more than $limit and set to a value for which links to be breaked $p_f=$_GET['p_f']; // To take care global variable if OFF if(!($p_f > 0)) { // This variable is set to zero for the first page $p_f = 0; } $p_fwd=$p_f+$p_limit; $p_back=$p_f-$p_limit; //////////// End of variables for advance paging /////////////// /////////////// Start the buttom links with Prev and next link with page numbers ///////////////// echo $space . $p_f . $space . $p_f . $space . $p_limit; $sql="select * FROM Complex order by Name limit " . $j . ", " . $k; // record set for subsequent page displays $result=$db->query($sql); echo "<table align = 'center' " . $width . "><tr><td align='left' width='20%'>"; //if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back'><font face='Verdana' size='2'>PREV $p_limit</font></a>"; } if($p_f<>0){print "<font face='Verdana' size='2'>PREV $p_limit</font>"; } echo "</td><td align='left' width='20%'>"; //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// if($back >=0 and ($back >=$p_f)) { //print "<a href='$page_name?start=$back&p_f=$p_f'><font face='Verdana' size='2'>PREV</font></a>"; print "<font face='Verdana' size='2'>PREV</font>"; } //////////////// Let us display the page links at center. We will not display the current page as a link /////////// echo "</td><td align=center width='20%'>"; for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit) { $j=$i+1;$k=$j+$limit; if($i <> $eu) { $i2=$i+$p_f; //echo " <a href='$page_name?start=$i&p_f=$p_f'><font face='Verdana' size='2'>Records $j - $k</font></a> "; echo " <font face='Verdana' size='2'>Records $j - $k</font> "; } else { $j=$i+1;$k=$j+$limit;echo "<font face='Verdana' size='2' > Records $j - $k</font>";} /// Current page is not displayed as link } echo "</td><td align='right' width='40%'>"; ///////////// If we are not in the last page then Next link will be displayed. Here we check that ///// if($this1 < $nume and $this1 <($p_f+$p_limit)) { //print "<a href='$page_name?start=$next&p_f=$p_f'><font face='Verdana' size='2'>NEXT $p_limit</font></a>"; print "<font face='Verdana' size='2'>NEXT $p_limit</font>"; } echo "</td><td align='right' width='40%'>"; if($p_fwd < $nume) { //print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd'><font face='Verdana' size='2'>NEXT $p_limit</font></a>"; print "<font face='Verdana' size='2'>NEXT $p_limit</font>"; } echo "</td></tr>"; echo "</table>"; $this->$beg = $j; $this->$end = $k; return $j;$k; } } ?> (3) Code from the top of the calling file: - It's lengthy, so I only posted the top portion. Note the last line, which contains addition within the variable declaration. No error is generated. <html> <head> <title>Complex Test7</title> <link href="css/styles.css" rel="stylesheet" type="text/css"> <! <link href="css/styles.php" rel="stylesheet" type="text/css"> </head> <body class="tablefonts"> <center>TEST7</center> <?php require ('PNS_Styles.php'); require ('class.dbConnect.php'); require ('class.tablePagination.php'); $db=' '; $result = ""; $empty = "<td><center><b> --- Empty --- </b></td></center>"; $page_name="complexTest6.php"; // If you use this code with a different page ( or file ) name then change this //$limit = 30; // No of records to be shown per page. $i=1; $j=0; $p_f=0; $k=$j+$limit;
  4. I'm trying to understand OOP and class construction. I have found many examples of building classes, but I am not clear on the purpose of one step: Here's some code: <?php class person { var $name; function set_name($new_name) { $this->name = $new_name; } function get_name() { return $this->name; } } ?> My question involves the statement: $this->name = $new_name. I understand the usage of $this and that the variable name is being set to the value of $new_name. Since $new_name has no value, it appears the statement may be used to create an element of the class. So, in the process of building a class, what does this statement do, and why is it required?
  5. Problem solved!!! I had a hunch and did a cut-and-paste of my scripts from this website to my editor, replaced the old files, and it worked -- I'm thinking now that hidden characters from my editor are to blame. That would explain a whole slew of unexpected and unsuccessful results over the past week. I have been using G-edit on Linux and Dreamweaver on Windows; I wouldn't think Dreamweaver would be responsible, so I'll be looking for a new Linux text editor. Any suggestions?
  6. Actually, that is great news - probably a system issue then. I'm using LAMP; OpenSuse11.3, Apache2.2.15 MySQL5.1.57 and PHP5.3.3. I suspect a configuration problem or maybe a missing extension because I can't get other PHP commands to work, such as mysqli_connect_error(). I am putting off a few obvious upgrades because I am right in the middle of a project, but if that is necessary to get things working, I'll make the jump.
  7. I am new to mysqli so I've been hitting the tutorials. I am following Stefan Mischook's OOP tutorial http://www.killerphp.com/tutorials/object-oriented-php/ and I am stuck on his example in Building OOP objects part 2. I've definitely invested the time trying to figure this out; I wonder if there is a PHP configuration missing on my installation. Any help would be greatly appreciated... The output is supposed to be Stefan but I get get_name(); ?> My code for class_lib.php: <?php class person { var $name = "stefan"; function get_name() { return $this->name; } } ?> My code for index.php: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <?php include("class_lib.php"); ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Killer Index.php</title> </head> <body> <?php $stefan = new person(); echo $stefan->get_name(); ?> </body> </html>
×
×
  • Create New...