Jump to content

chocopi

Members
  • Posts

    551
  • Joined

  • Last visited

    Never

About chocopi

  • Birthday 08/22/1991

Profile Information

  • Gender
    Male
  • Location
    Bournemouth, South of England

chocopi's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Thanks for the replies. I've just been a bit of testing with the static and your right Once i re-read the static page and realised i needed to use self::$var instead of $this->var it became much simplier. Edit: Seeing how mikesta707 has replied while I was, i nearly missed it I must remember to read the user notes on the php.net, sorry for wasting your time That was laziness on my part Anyways Thanks [ SOLVED ]
  2. So I had a quick look at this and thought I would give it a try function newHeight($heightMum, $heightDad) { $handsMum = calcHands($heightMum); $handsDad = calcHands($heightDad); $handsAvg = ($handsMum + $handsDad) / 2; $handsRand = mt_rand(-2, 2) / 10 * 4; return checkHeight(round(($handsAvg + $handsRand) / 4, 1)); } function calcHands($height) { $heightInt = floor($height); $heightDec = $height - $heightInt; return ($heightInt * 4) + ($heightDec * 4); } function checkHeight($height) { $heightDec = $height - floor($height); $height = ($heightDec > 0.3) ? floor($height) + 1 : $height; return min(max($height, 12), 18); } $heightMum = 13.2; $heightDad = 15.1; echo newHeight($heightMum, $heightDad); My logic was to try and find the average between the hands value of each horse and then add the random value. However, from the small testing I did I never saw .3 come up probably due to my poor maths I hope this helps in some way Edit: This wasn't solved when I went to reply :S
  3. Is there anyway for two (or more) child classes to inherit a parent class with there only be one iteration of the parent class. What I mean is, if child class 1 changes one of the parent properties I would like child class 2 to have access to that variable. Obviously when you inherit the parent class a new object is created therefore causing both the child classes access to clones of the parent. I know that i could global the parent object within each of the child methods, but seems like poor coding standards to me I've had a quick check on google, php.net and these forums, but I'm not really sure what to search for :-\ I'm sure there is a very simple solution to this which I have overlooked Any help will be greatly appreciated ps. In case it matters I'm using php version 5.3.0
  4. Just use something along the lines of: <?php $path = "./images/"; $dh = opendir($path); $NumOfFiles = 0; while ($file = readdir($dh)) { if(eregi("(.*\.jpg)",$file)) { $NumOfFiles++; } } closedir($dh); echo $NumOfFiles; ?> It's untested but it should work, if my memory serves haven't done php in a while. ~ Chocopi
  5. what you could do on the redirect is use a $_GET to display the error if($_POST) { if($_POST['captcha'] != $_SESSION['captcha']) { header("Location: yourpage.php?captcha=error"); } else { echo "Captcha Correct"; } } then on yourpage.php have some code somewhere that will display the error if($_GET['captcha'] == 'error') { echo "Your captcha was incorrect"; } something like that should work Hope it Helps ~ Chocopi
  6. doesnt the code you showed a few posts back work ? if($_POST) { if($_POST['captcha'] != $_SESSION['captcha']) { die("Incorrect Code"); } else { echo "Captcha Correct"; } } All you have to do is change the die() to a redirect where the page says "incorrect capthca" or just show the same page and show the error message. Hope that help ~ Chocopi
  7. I think this might be what you are looking for. It basically goes through all the tables in your database and then takes the column sitename (which obviusly you will need to change to suit your needs) and goes through each value. It is all added to the variable $string which is then written into the db.txt which you will need to create one and name it what ever you want. <?php $db_host = ''; $db_username = ''; $db_password = ''; $db_database = ''; $db_connection = mysql_connect($db_host,$db_username,$db_password) or die(mysql_error()); mysql_select_db($db_database) or die(mysql_error()); $string = ""; $sql = "SHOW TABLES FROM $db_database"; $result = mysql_query($sql) or die(mysql_error()); while($table_name = mysql_fetch_array($result)) { $sql2 = "SELECT sitename FROM $table_name[0]"; $result2 = mysql_query($sql2) or die(mysql_error()); $string .= "\n{$table_name[0]}\n"; while($column_name = mysql_fetch_array($result2)) { $string .= "{$column_name[0]}\n"; } } $file = "db.txt"; if(is_writable($file)) { if(!$handle = fopen($file, 'w')) { die("Cannot open file ($file)"); } if(fwrite($handle, $string) === FALSE) { die("Cannot write to file ($file)"); } echo "Success, wrote to file ($file)"; fclose($handle); } else { echo "The file $file is not writable"; } ?> I hope it helps ~ Chocopi
  8. well can we see some code please but what you basically need is a $_GET which will get your start point and use that plus a Limit in your mysql query. ~ Chocopi
  9. Just google it Google Search <html> <head> <script language="JavaScript"> function Disab (val) { if(val=="1") {form1.Submit.disabled=true} if(val=="2") {form1.Button.disabled=true} } </script> </head> <body> <form name="form1" method="post" action="" enctype="text/plain"> <input type="submit" name="Submit" value="Submit" onClick="Disab (1)"> <input type="button" name="Button" value="Button" onClick="Disab (2)"> </form> </body> </html> That is a form with 2 buttons one will disable when clicked and load the form while the other will just disable itself. I hope thats what you were looking for ~ Chocopi
  10. you could use switch <?php $nick = $_SESSION["myusername2"]; $query="SELECT access FROM `user` WHERE 'username' = $nick"; $result=mysql_query($query) or die(hmm); $num = mysql_num_rows($result); switch($result['access']) { case admin: // admin page break; case mod: // mod page break; case normal: // normal page break; } ?> if you get rid of the break's then the admin would see admin,mod,normal and mod would see mod,normal and normal would just see normal. If that makes sense replace admin, mod and normal with whatever values you are expecting. Hope that helps ~ Chocopi
  11. Is it because your not actually sending the email you are just storing it in a variable shouldn't it be: mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); instead of $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); ~ Chocopi
  12. no wonder imagefilter doesnt work You should probably think about upgrading to php 5 or you will need to take Wes up on his offer to make you his own image filter function ~ Chocopi
  13. I know you are just trying to fix your code, but I was messing around with a mixture of codes and ended up with this: <?php $base_url = $_SERVER['PHP_SELF']; // this is just to get the page your on $num_items = 121; // this is the total amount of results $per_page = 5; // this is obviously the amount of results you want on each page $start_item = (empty($_GET['start'])) ? 1 : $_GET['start']; // this is the get to get where to start function pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE) { $begin_end = 3; // this is how many numbers will be placed at the beggining ie 1,2,3 ... 8,9,10, if 5 then 1,2,3,4,5 .... 11,12,13,14,15 etc $from_middle = 1; // how many results wil be displayed in middle ie for 1 ... 7,8,9 ... if 3 then 7,8,9,10,11,12,13 $total_pages = ceil($num_items/$per_page); if ( $total_pages == 1 ) { return ''; } $on_page = floor($start_item / $per_page) + 1; $page_string = ''; if ( $total_pages > ((2*($begin_end + $from_middle)) + 2) ) { $init_page_max = ( $total_pages > $begin_end ) ? $begin_end : $total_pages; for($i = 1; $i < $init_page_max + 1; $i++) { $page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' .$base_url . "?start=" . ( ( $i - 1 ) * $per_page ) . '">' . $i . '</a>'; if ( $i < $init_page_max ) { $page_string .= ", "; } } if ( $total_pages > $begin_end ) { if ( $on_page > 1 && $on_page < $total_pages ) { $page_string .= ( $on_page > ($begin_end + $from_middle + 1) ) ? ' ... ' : ', '; $init_page_min = ( $on_page > ($begin_end + $from_middle) ) ? $on_page : ($begin_end + $from_middle + 1); $init_page_max = ( $on_page < $total_pages - ($begin_end + $from_middle) ) ? $on_page : $total_pages - ($begin_end + $from_middle); for($i = $init_page_min - $from_middle; $i < $init_page_max + ($from_middle + 1); $i++) { $page_string .= ($i == $on_page) ? '<b>' . $i . '</b>' : '<a href="' . $base_url . "?start=" . ( ( $i - 1 ) * $per_page ) . '">' . $i . '</a>'; if ( $i < $init_page_max + $from_middle ) { $page_string .= ', '; } } $page_string .= ( $on_page < $total_pages - ($begin_end + $from_middle) ) ? ' ... ' : ', '; } else { $page_string .= ' ... '; } for($i = $total_pages - ($begin_end - 1); $i < $total_pages + 1; $i++) { $page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . $base_url . "?start=" . ( ( $i - 1 ) * $per_page ) . '">' . $i . '</a>'; if( $i < $total_pages ) { $page_string .= ", "; } } } } else { for($i = 1; $i < $total_pages + 1; $i++) { $page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . $base_url . "?start=" . ( ( $i - 1 ) * $per_page ) . '">' . $i . '</a>'; if ( $i < $total_pages ) { $page_string .= ', '; } } } if ( $add_prevnext_text ) { if ( $on_page > 1 ) { $page_string = ' <a href="' . $base_url . "?start=" . ( ( $on_page - 2 ) * $per_page ) . '">Previous</a> ' . $page_string; } if ( $on_page < $total_pages ) { $page_string .= ' <a href="' . $base_url . "?start=" . ( $on_page * $per_page ) . '">Next</a>'; } } $page_string = 'Go To ' . $page_string; return $page_string; } echo pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE); // set to false if you dont want next and prev link ?> I haven't found any problems with it yet So I thought I would throw this out there as it is nearly impossible to find a good pagination script. Well I hope someone finds it useful ~ Chocopi
×
×
  • 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.