
chocopi
Members-
Posts
551 -
Joined
-
Last visited
Never
Everything posted by chocopi
-
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 ]
-
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
-
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
-
How to get the number of jpeg files on a folder ?
chocopi replied to 2levelsabove's topic in PHP Coding Help
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 -
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
-
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
-
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
-
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
-
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
-
So is it working how you want now ?
-
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
-
[SOLVED] PHP_SELF: Just the directory + page name.
chocopi replied to Michan's topic in PHP Coding Help
look at this Path Info -
Somebody. Please help me with this contact form, ITS DRIVING ME CRAZY.
chocopi replied to crj900's topic in PHP Coding Help
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 -
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
-
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
-
ok try replacing $PHP_SELF with $_SERVER['PHP_SELF'] Also, if there is no record in the database then it should fill the textarea with nothing. So it should still update the database with whatever you put into the textarea. But you could try replacing $row = mysql_fetch_assoc($query) or die(mysql_error()); $message = $row['welcome']; with while ($row = mysql_fetch_assoc($query)) { $message = $row['welcome']; $check = 1; } and then replace <?php if($_POST) { $message = $_POST['message']; $update = "UPDATE welcome SET welcome='$message' WHERE club_id='$club_id'" or die(mysql_error()); mysql_query($update) or die(mysql_error()); echo "Message Updated!"; } ?> with <?php if($_POST) { $message = $_POST['message']; if($check == 1) { $update = "UPDATE welcome SET welcome='$message' WHERE club_id='$club_id'" or die(mysql_error()); mysql_query($update) or die(mysql_error()); echo "Message Updated!"; } else if($check != 1) { $insert = "INSERT INTO welcome (welcome) VALUES ('$message')" mysql_query($insert) or die(mysql_errror()); echo "New Message Created!"; } } ?> I think that might work ~ Chocopi
-
oh rite yea, sorry i meant to change that It is the query you use to get the message from the database. so the code should be something like this: <?php // connect to db $query = mysql_query("SELECT welcome FROM welcome WHERE club_id='$club_id'") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); $message = $row['welcome']; echo "<form method=\"post\" action=\"{$PHP_SELF}\">"; echo "<textarea name=\"message\">{$message}</textarea>"; echo "<input type=\"submit\" />"; echo "</form>"; if($_POST) { $message = $_POST['message']; $update = "UPDATE welcome SET welcome='$message' WHERE club_id='$club_id'" or die(mysql_error()); mysql_query($update) or die(mysql_error()); echo "Message Updated!"; } ?> I think those are the queries you would want. First one selects the message you want to edit from the database and then puts that into the textarea. Second one gets the posted data after the user submits the form and inserts it into the database. Hope that clears it up for you ~ Chocopi
-
just have a page with a textarea and get the admin to write the message in there then when they submit the form it updates your table and on edit just fill the textarea with the previous message then do the same as above. <?php // connect to db $query = // some query $row = mysql_fetch_assoc($query) or die (mysql_error()); $message = $row['fieldname']; echo "<form method=\"post\" action=\"{$PHP_SELF}\">"; echo "<textarea name=\"message\">{$message}</textarea>"; echo "<input type=\"submit\" />"; echo "</form>"; if($_POST) { $message = $_POST['message']; $update = "UPDATE table SET fieldname='$message' WHERE something='something'" or die (mysql_error()); mysql_query($update) or die (mysql_error()); echo "Message Updated!"; } ?> Something along those lines, I think ~ Chocopi
-
much smoother I just noticed that if you type in something that is to long then your gradient width stops or it might be that the gradient isnt centered along with the image Long Link
-
Yea this is awesome !!! The only I would say is that it looks kind of strange when you have letters that hang below normal eg lowercase p and g. Also, the gradient seems to just end and doesnt fade away smoothly, but thats probably me just being picky. Nice Code
-
[SOLVED] escaping characters and bringing them back in output
chocopi replied to polemios's topic in PHP Coding Help
probably because the magic quotes have been turned on, on your server but not locally. -
ok i've been messing around with the code for about 10 mins and I think it's what you want <?php error_reporting(E_ALL); $teams1 = array("x","y","g","h","a","b"); $teams2 = $teams1; $i = 0; foreach($teams1 as $team1) { foreach($teams2 as $team2) { if((array_keys($teams2, $team2)) > (array_keys($teams1, $team1))) { $matches[$i] = "{$team1} Vs {$team2}"; $i++; } } } for($j = 0; $j <= 2; $j++) { shuffle($matches); $k = $j+1; echo "<b>Week {$k}</b><br />"; foreach($matches as $match) { echo "{$match} <br />"; } } ?> Well I hope that helps, it's not the prettiest code ever, but hopefully it does the job ~ Chocopi
-
If Mattal's idea doesn't work then I think it might be something to do with the mysql_num_rows() so try using this instead: <?php error_reporting(E_ALL); require_once("page_header.php"); if($_POST) { $errors = 0; // set errors which will be used to check if the login was incorrect $username = mysql_real_escape_string($_POST['username']); // get the posted username and set to variable $password = mysql_real_escape_string($_POST['password']); // get the posted password and set to variable $query = mysql_query("SELECT id,unique_code FROM login_pib WHERE username='$username' && password='$password'") or die(mysql_error()); // check to see if username and password match database while($row = mysql_fetch_assoc($query)) // do a while statement to get the values { $id = $row['id']; // set the user id from the database to a variable $code = $row['unique_code']; // set the code from the database to a variable session_start(); // start the sesssion so we can check later to see if they are logged in as the right user $_SESSION['id'] = $id; // set the id to the session $_SESSION['username'] = $username; // set the username to the session $_SESSION['password'] = $password; // set the password to the sesison $_SESSION['code'] = $code; // set the unique code to the session $location = "users/{$username}/index.php"; // create the location for the user header("Location: $location"); // redirect the user to their folder } $errors++; // if the user is not redirected then increment errors } ?> <form name="form" method="post" action="<?php echo $PHP_SELF; ?>"> <input type="text" name="username" /><br /> <input type="password" name="password" /><br /> <input type="submit" name="submit" /> </form> <?php if($errors > 0) // check if there were errors { die("Your login was incorrect !"); // if there are errors kill the script, but after the form has been outputted otherwise the user will see a blank screen } ?> Now if Mattal's idea doesn't work then I hope this should solve the current problem ~ Chocopi
-
Also, shouldnt this: $row[username] be $row['username'] or $row[$username] Theres a bit of discussion in this topic http://www.phpfreaks.com/forums/index.php/topic,163268.msg715688.html#msg715688
-
what variables are the numbers stored in for listed and users ???