Jump to content

xangelo

Members
  • Posts

    102
  • Joined

  • Last visited

    Never

Everything posted by xangelo

  1. It looks like you're talking about chaining. Placing a function within another function (which is already in a class) would do nothing except organize how you would call your code.
  2. I'm sure something like that makes perfect sense for Google however. Micro-optimizations don't commonly have a place in regular day-to-day programming projects, but when you're dealing with hundreds of thousands of users, then every little bit will help.
  3. I am not 100% on this, but the static keyword would preserve an items state throughout instances..
  4. Are there certain rules to handling the addition of the random number? IE if it is over .3 it will always round up to the next nearest whole number?
  5. You're not actually gathering the values in process.php. Since you're using the POST method, your code should look more like this: <?php $host="localhost"; // Host name $username="xxxx"; // Mysql username $password="xxxxx"; // Mysql password $db_name="xxxx"; // Database name $tbl_name="xxxx"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $xusername = $_POST['xusername']; $bankbalance = $_POST['bankbalance']; $id = $_POST['id']; // update data in mysql database $sql="UPDATE $tbl_name SET xusername='$xusername', bankbalance='$bankbalance' WHERE id='$id' "; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Update Was Successful"; echo "<BR>"; echo "<a href='index.php'>Click To Go Back To Main Bank Page!</a>"; } else { echo "ERROR"; } ?> That will load the values from the previous page into the variables you used. However, note that the code above does not contain ANY error checking what-so-ever. Meaning if you went to process.php it would still process the page and xusername/bankbalance/id would all be empty. Also, you have to add your own value-checks (strip_tags(), mysql_escape_string() etc)
  6. His problem was this: I looked through the code and tested it out and it worked perfectly for me. Sorry TheJoey, I'm just not seeing any problems.
  7. If you don't have a reason to place a function in a class, it remains a function instead of a method. You can have class and function folders, they just shouldn't contain similar functions/classes. For example you could create a function that would just include a bunch of config files for you and you could just call that. Putting that into a class might be a bit overkill.
  8. SaturdayNightSpecial, place the function code outside your do-while loop. The error you are encountering is because during the second iteration through the loop it encounters the function and tries to create it. However, it already exists, so it throws that error. You can put it right before the start of the do { section.
  9. Just a note with thetabs, in firefox (3.5) the last link (Life) doesn't line up properly when you hover over it. And when you click on it, the tab isn't selected.
  10. It seems like you've got everything organized in a pretty straightforward manner. I'm not sure about everyone else, but I think as long as you keep things easy to understand and group like files, the file structure isn't as important. If you are worried about future developers having to tinker with the code, a quick readme file including a description of the folders could be handy.
  11. The beauty of functions is that they don't need to show up where you use them. For example, you could have all your functions at the bottom of the page. To use it, you would just do this: echo excerpt($row_rs_news_content['nfarticle'],50); You don't need to modify the function in any way for it to work. Functions are like separate little blocks of code. You just have to pass them some values, and they work with them and spit out the desired result. I don't like posting personal links, but I did a quick explanation of this earlier today on my website. It goes through a complete breakdown of the function and how it works: http://wheremy.feethavebeen.com/?p=146
  12. You've flipped the in_array arguments. if(in_array($exp, $all_cats) Should actually be if(in_array($all_cats, $exp) The first value in in_array is what you're looking for. The second is the array you're looking for it in. http://us2.php.net/manual/en/function.in-array.php
  13. A quick interesting problem Here's a quick solution: function excerpt($message,$size = 100){ $message = substr($message,0,$size); $point = strrpos($message,' '); $message = substr($message,0,$point); return $message.' ...'; } That function will accept any string and an integer size. It then runs it through the substr function to ensure that the output is at MOST $size. Then it gets the position of the last " " character and reruns the substr function with this new value. It then returns the excerpt with a ' ...' appended.
  14. I'm not quite sure what you mean, but you can pass additional variables through the url so that it looks like this: index.php?rid=5&print_status=0 And you can get those values like this: <?php $rid = $_GET['rid']; $print_status = $_GET['print_status']; ?> Don't forget to sanitize your input though.
  15. I think what you're looking for is something like http://ca.php.net/manual/en/function.substr.php which will return a section of a string. However, I'd suggest looking into creating your own version of the function as that way will cut off words.. perhaps substr to capture the first 200 characters, and then drop the characters after the last space and replace it with .... You can couple substr with strrpos http://ca.php.net/manual/en/function.strrpos.php to achieve this. As for reloading the text without reloading the page, sadly, without javascript your'e out of luck. However, if the content stays fairly static, I'd suggest implementing a caching system. That way at least you don't have to poll the database every refresh.
  16. So essentially you have a multitude of items and only start/end dates? That shouldn't be too hard to whip up in PHP
  17. Just out of curiosity, what was the output of print_r()?
  18. A big pro with using getter/setter methods is that it provides a bit of future-proofing. Say a few months down the line you need to make an update to your code and modify what happens to the variable. For example: <?php class Robot{ var $numFingers = 5; } Directly accessing the member would give you the right answer, until you decided that you were adding the arms functions. Now, $numFingers is the number of fingers on each arm. So the total number of fingers would actually be $numFingers*$numArms. If you were directly accessing the data then you would have to apply the multiplication outside the scope of the class. However, if you had a getter/setter method, you could just update your setter method to multiply $numArms*$numFingers and then you wouldn't need to change any code that required those values. I hope the example helped visualize it a little.
  19. Native Binding is an ambiguous term that could mean anything from "If you use PHP, this app will work with it" to "This app contains a full PHP API that you can use to develop your own app"
  20. I haven't really had time to look over the class, but a quick search turned up this: http://www.phpclasses.org/browse/package/2737.html. It might be useful to you.. if not, contact me via PM and perhaps we can try and work something out.
  21. The fact that $icon[$i] in your for each makes me think you have a two dimensional array being set.. therefore, $icons[$i] will give you the Array value but $icon[$i] (which is like saying $icons[$x][$i]) is a value.
  22. Normally what they do is run it through the one-way encryption and store the hashed value. Then if you ever enter a password again, it runs it through the encryption and checks it against the stored value.
  23. The easiest way would be to do this: $days[] = date("d", strtotime($charts['posted'])); sort($days); $day = implode(',', $days); sort()
  24. <?php include("config.inc.php"); $pics_per_row = 5; $result = mysql_query("select * from gallery_photos"); $inc = 0; echo '<table>'; while($row = mysql_fetch_array($result)) { if($inc%$pics_per_row == 0) { echo '<tr>'; } echo '<td><a href="photos/' . $row["photo_filename"] . '"><img src="photos/tb_' . $row["photo_filename"] . '" border="1" /></a><br /></td>'; if($inc%$pics_per_row == 0) { echo '<tr>'; } $inc++; } echo '</table>';
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.