
Drummin
Members-
Posts
1,004 -
Joined
-
Last visited
Everything posted by Drummin
-
If you are talking about AS you put each number in, it would update the count of numbers, no, not with php. You'd need some Javascript for that. As for duplicates in original main list not being removed, they are everytime I've tested it. I put in 1 2 1 4 ...and then filter out 1, I'm left with 2 4 Can you give me any example of numbers where it hasn't worked?
-
You can always use count(). <?php if (isset($_POST['listnumbers'])){ $Newlist = explode(PHP_EOL, trim($_POST['listnumbers'])); $before_count = count($Newlist); $Searchlist = explode(PHP_EOL, trim($_POST['searchnumbers'])); $Newlist = array_diff($Newlist,$Searchlist); $after_count = count($Newlist); $phone_number_list = implode("<br />",$Newlist); } echo "Before: $before_count After: $after_count"; ?>
-
Huh? You put in these number into the first textarea and 6 into the second textarea and it pulls that six out. What are you talking about? can you give me some examples? 12345 1234576 6 564476 3433243 66655434
-
Copy that isset echo line I have between the textarea tags an place where you want it. If you are going to use it for display, you'll probably want to change that last line to implode with a break tag. $phone_number_list = implode("<br />",$Newlist);
-
generating unique password without going to db?
Drummin replied to stijn0713's topic in PHP Coding Help
I had grabbed this off the web some time ago and used in in several situations like this. Might work for you. <?php //Generate a random $min=6; // minimum length of keycode $max=8; // maximum length of keycode $kcode=""; // to store generated keycode for($i=0;$i<rand($min,$max);$i++){ $num=rand(48,122); if(($num > 97 && $num < 122)){ $kcode.=chr($num); } else if(($num > 65 && $num < 90)){ $kcode.=chr($num); } else if(($num >48 && $num < 57)){ $kcode.=chr($num); } else if($num==95){ $kcode.=chr($num); } else{ $i--; } } echo "$kcode"; ?> -
I'm not aware of limitations to array_diff but not tried it with a large list. Did you try it?
-
This should do it. <?php if (isset($_POST['listnumbers'])){ $Newlist = explode(PHP_EOL, trim($_POST['listnumbers'])); $Searchlist = explode(PHP_EOL, trim($_POST['searchnumbers'])); $Newlist = array_diff($Newlist,$Searchlist); $phone_number_list = implode(PHP_EOL,$Newlist); } ?> <html> <body> <form method="post" action=""> <textarea name="listnumbers"><?php if (isset($phone_number_list)){echo "$phone_number_list";} ?> </textarea><br /> <textarea name="searchnumbers"></textarea><br /> <input type="submit" value="Check Number" /> </form> </body> </html>
-
As pointed out, for single number removal a simple preg_replace will do the job. <?php if (isset($_POST['listnumbers'])){ $phone_number_list = trim($_POST['listnumbers']); $phone_number = trim($_POST['searchnumber']); $phone_number_list = preg_replace("/$phone_number/", "", $phone_number_list); $phone_number_list = str_replace(PHP_EOL.PHP_EOL, PHP_EOL, $phone_number_list); } ?> <html> <body> <form method="post" action=""> <textarea name="listnumbers"><?php if (isset($phone_number_list)){echo "$phone_number_list";} ?> </textarea><br /> <textarea name="searchnumber"></textarea><br /> <input type="submit" value="Check Number" /> </form> </body> </html> If however if your needing to remove a list of numbers from another list of numbers this approach won't work and you will probably need to build an array for each input and then filter out matches within a foreach loop.
-
Maybe this is a little over the top, creating arrays etc. <?php if (isset($_POST['listnumbers'])){ $listnumbers = nl2br(trim($_POST['listnumbers'])); $listnumbers = explode('<br />', $listnumbers); $Newlist=array(); foreach ($listnumbers as $numbers){ $numbers = str_replace("\r", "", $numbers); $numbers = str_replace("\n", "", $numbers); $numbers = preg_replace('~^(\<br /\>,/\n)+~', '', $numbers); $Newlist[] = $numbers; } $searchnumber = trim($_POST['searchnumber']); if (in_array($searchnumber,$Newlist)){ $number_key = array_search($searchnumber,$Newlist); unset($Newlist[$number_key]); } } ?> <html> <body> <?php echo "<pre>"; echo "<br />listnumbers<br />"; print_r($listnumbers); echo "<br />Newlist<br />"; print_r($Newlist); echo "<br />POST<br />"; print_r($_POST); echo "</pre>"; ?> <form method="post" action=""> <textarea name="listnumbers"> <?php echo (isset($Newlist)? implode(' ', $Newlist):''); ?> </textarea><br /> <textarea name="searchnumber"></textarea><br /> <input type="submit" value="Check Number" /> </form> </body> </html>
-
Of course, good spotting jazzman1. Unless you really need GET for some reason, change method to post.
-
Not sure, but isn't "class" a reserved word? Might need to change table name to "classes" or something.
-
Looking at your other post I see you are wishing to loop through variations so you have a select box for each type. I think you could probably store things a little better but won't get into that. Here's a version, doing three queries and building one array. Should be close to what you need. <?php function product() { //Import product varible global $product; $product = mysql_real_escape_string($product); //convert product value into a title $value = str_replace("-"," ",$product); //Connect to database and get the required product. $sql = "SELECT id, category, name, image, description, price "; $sql .= "FROM store_products "; $sql .= "WHERE name = '$value' ORDER BY id ASC"; $result = mysql_query($sql) or die(mysql_error()); //If the product is not found in the database. if (mysql_num_rows($result) == 0) { //Display a message echo '<h1>' . "This product doesent exist" . '</h1>' . "\n"; //If products are found in database. } else { while ($row = mysql_fetch_array($result)) { $store_products[$row['id']] = array("name" => $row['name'], "image" => $row['image'], "category" => $row['category'], "description"=> $row['description'], "price" => $row['price'],); //Get variations for product and add to array $sql2 = "SELECT title, variation, price "; $sql2 .= "FROM store_variations "; $sql2 .= "WHERE product = '{$row['name']}'"; $result2 = mysql_query($sql2) or die(mysql_error()); if (mysql_num_rows($result2) != 0){ while ($row2 = mysql_fetch_array($result2)) { $store_products[$row['id']]['variation'][] = array("title" =>$row2['title'],"variation" =>$row2['variation'],"price" =>$row2['price']); } } //Get variation values for product and add to array $sql3 = "SELECT title, variation, price "; $sql3 .= "FROM store_variations_values "; $sql3 .= "WHERE product = '{$row['name']}'"; $result3 = mysql_query($sql3) or die(mysql_error()); if (mysql_num_rows($result3) != 0){ while ($row3 = mysql_fetch_array($result3)) { $store_products[$row['id']]['variation_values'][] = array("title" =>$row3['title'],"variation" =>$row3['variation'],"price" =>$row3['price']); } } } } //Show Product form. foreach ($store_products as $store_product){ echo '<form method="post" action="">' . "\n"; echo '<div id ="StoreCol1">' . "\n"; echo '<h1>' . $store_product['name'] . '</h1>' . "\n"; echo '<input type="hidden" name="name" value="' . $store_product['name'] . '">' . "\n"; echo '<a href="public/images/' . $store_product['image'] . '" target="_blank"><img src="public/images/' . $store_product['image'] . '" height="200" width="300" style="border:none;" /></a>' . "\n"; echo '<p>' . $store_product['description'] . '</p>' . "\n"; echo '<a href="store.php?category=' . $store_product['category'] . '">' . "Go Back" . '</a>' . "\n"; echo '</div>' . "\n"; echo '<div id="StoreCol2">' . "\n"; echo '<p>' . "Any extra charges will be displayed and added in your cart." . '</p>' . "\n"; echo '<p>' . '<b>' . "Price: £" . $store_product['price'] . '</b>' . "</p>" . "\n"; echo '<p>' . "Excludes postage and packaging." . '</p>' . "\n"; //Add options here foreach($store_product['variation'] as $variation) { echo '<p>' . $variation['title'] . ": "; echo '<select name = "variation_option" >' . "\n"; foreach($store_product['variation_values'] as $variation_values) { if ($variation['title']==$variation_values['title']){ echo '<option value= "'.$variation_values['variation'].'">'.$variation_values['variation'].'</option>' . "\n"; } } echo '</select></p>'; } echo '</div>' . "\n"; echo '</form>'; } //Uncomment to see array /* echo "<pre>"; print_r($store_products); echo "</pre>"; */ } ?>
-
Looks like you are holding same fields in store_variations and store_variations_values. In any case, I made a variation of your code making two queries and building one array. I normally don't like nested queries but building that sub variations array was giving me trouble without it. I wouldn't expect this to work (out of the box) as I'm not querying the store_variations_values table but maybe it will get you moving forward. <?php function product() { //Import product varible global $product; $product = mysql_real_escape_string($product); //convert product value into a title $value = str_replace("-"," ",$product); //Connect to database and get the required product. $sql = "SELECT id, category, name, image, description, price "; $sql .= "FROM store_products "; $sql .= "WHERE name = '$value' ORDER BY id ASC"; $result = mysql_query($sql) or die(mysql_error()); //If the product is not found in the database. if (mysql_num_rows($result) == 0) { //Display a message echo '<h1>' . "This product doesent exist" . '</h1>' . "\n"; //If products are found in database. } else { while ($row = mysql_fetch_array($result)) { $store_products[$row['id']] = array("name" => $row['name'], "image" => $row['image'], "category" => $row['category'], "description"=> $row['description'], "price" => $row['price'],); //Get variations for product and add to array $sql2 = "SELECT title, variation, price "; $sql2 .= "FROM store_variations "; $sql2 .= "WHERE product = '{$row['name']}'"; $result2 = mysql_query($sql2) or die(mysql_error()); if (mysql_num_rows($result2) != 0){ while ($row2 = mysql_fetch_array($result2)) { $store_products[$row['id']]['variation'][] = array("title" =>$row2['title'],"variation" =>$row2['variation'],"price" =>$row2['price']); } } } } //Show Product form. foreach ($store_products as $store_product){ echo '<form method="post" action="">' . "\n"; echo '<div id ="StoreCol1">' . "\n"; echo '<h1>' . $store_product['name'] . '</h1>' . "\n"; echo '<input type="hidden" name="name" value="' . $store_product['name'] . '">' . "\n"; echo '<a href="public/images/' . $store_product['image'] . '" target="_blank"><img src="public/images/' . $store_product['image'] . '" height="200" width="300" style="border:none;" /></a>' . "\n"; echo '<p>' . $store_product['description'] . '</p>' . "\n"; echo '<a href="store.php?category=' . $store_product['category'] . '">' . "Go Back" . '</a>' . "\n"; echo '</div>' . "\n"; echo '<div id="StoreCol2">' . "\n"; echo '<p>' . "Any extra charges will be displayed and added in your cart." . '</p>' . "\n"; echo '<p>' . '<b>' . "Price: £" . $store_product['price'] . '</b>' . "</p>" . "\n"; echo '<p>' . "Excludes postage and packaging." . '</p>' . "\n"; //Add options here echo '<p>' . $store_product['variation'][0]['title'] . ": "; echo '<select name = "variation_option" >' . "\n"; foreach($store_product['variation'] as $variation) { echo '<option value= "'.$variation['variation'].'">'.$variation['variation'].'</option>' . "\n"; } echo '</select></p>'; echo '</div>' . "\n"; echo '</form>'; } //Uncomment to see array /* echo "<pre>"; print_r($store_products); echo "</pre>"; */ } ?> Note, I have not looked at your other post.
-
Do I need to ask this question again? Did you add the error IF statement like I said? That should stop emails from being sent if file not loaded. $file_name = "{$_FILES['file_upload']['name']}"; $tmp_name = "{$_FILES['file_upload']['tmp_name']}"; $file_type = "{$_FILES['file_upload']['type']}"; if ($_FILES['file_upload']['error']!=0){ $error="No File Uploaded!"; }
-
I Just tested the mailer using this header section and it worked fine, though I do not use Outlook so can't test that part. $headers = "From: $from". PHP_EOL; $headers .= "X-Sender: $from". PHP_EOL; $headers .= "X-Priority: 3". PHP_EOL; $headers .= "X-Mailer: php". PHP_EOL; //declarinf mutlipart boundary type $headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$uid."\"". PHP_EOL. PHP_EOL; $headers .= "this is a message in multipart MIME format.". PHP_EOL. PHP_EOL; $headers .= "--PHP-mixed-".$uid."". PHP_EOL; $headers .= "Content-Type: multipart/alternative; boundary=\"PHP-alt-".$uid."\"". PHP_EOL. PHP_EOL; $headers .= "--PHP-alt-".$uid."". PHP_EOL; $headers .= "Content-type: text/html; charset=utf-8". PHP_EOL; $headers .= "Content-Transfer-Encoding: 7bit". PHP_EOL. PHP_EOL; $headers .= "$mail_content". PHP_EOL. PHP_EOL; $headers .= "--PHP-alt-".$uid."--". PHP_EOL; //file attachment $headers .= "--PHP-mixed-".$uid."". PHP_EOL; $headers.="Content-Type:".$file_type."; name=\"".$file_name."\"". PHP_EOL; $headers.="Content-Transfer-Encoding: Base64". PHP_EOL; $headers.="Content-Disposition: attachment; filename=\"".$file_name."\"". PHP_EOL; $headers.=$content."". PHP_EOL. PHP_EOL; $headers .= "--PHP-mixed-".$uid."--"; $mail_content="";
-
I saw somewhere where they used PHP_EOL for line breaks to fix the issue between user platforms. Not tested. $headers = "MIME-Version: 1.0" . PHP_EOL;
-
Thank you both for your help.
-
This is for a simulator where you set a target percent to run numbers through. As mentioned the plus or minus number will also be set in a final application. I'm looking for a way to accurately represent daily averages within these parameters and the average result over thirty days is the target percent.
-
Is there a way to create a random daily percent, + or - some value that will accurately return a target percent average for a given month. In this code I have a target goal of 15 and a plus or minus value of 4. I'm using rand() to create value for the day. However when running and tallying the result I get anywhere from 13.7 to 16.3 for example. Is there any way to do this and get a true average that matches the goal amount? <?php $goal=15; $c=4; $rhigh=$goal+$c; $rlow=$goal-$c; echo "$goal<br />"; $total=""; for($i=1; $i<=30; $i++){ $percent=rand($rlow,$rhigh); echo "Day $i Percent: $percent<br />"; $total +=$percent; } $result=$total/30; $result=number_format($result, 1, '.', ''); echo "$result"; ?>
-
Having an issue with UPDATING SQL Database via PHP Table
Drummin replied to mbb87's topic in PHP Coding Help
You are not reading the replies. 1. Fix the back-ticks issue. $query = "UPDATE `players` SET `block` = `players`.`pl_id` IN ({$checked_players_list})"; 2. Change callback function to interval. $checked_players_list = implode(', ', array_map('intval', $_POST['pl_id'])); -
You already have several sessions counting. $miss_total = $_SESSION["totalGuess"] - count($_SESSION["matches"]); So $_SESSION["totalGuess"] is going up with each answer and you would format the code much like I did using the $miss_total variable for showing each image.
-
Something like this should work. <?php session_start(); $wordList = array( 'table', 'curtain', 'printer', 'guitar', 'piano', 'dragon', 'pack', 'bottle', 'shirt', 'picture' ); if (!isset($_SESSION['word']) || isset($_POST['reset'])){ $wordkey=array_rand($wordList); $word=$wordList[$wordkey]; $_SESSION['word']=$word; $_SESSION["totalGuess"]=0; $_SESSION["matches"]=array(); }else{ $word=$_SESSION['word']; } $wordlength = strlen($word); $totalGuess = (!isset($_SESSION["totalGuess"])? 0 : $_SESSION["totalGuess"]); //create array of letters in word $word_array = str_split($word); //Check post against word_array //if (isset($_POST['guess']) && $totalGuess<=$wordlength){ if (isset($_POST['guess'])){ $letter = trim($_POST['guessletter']); $matchkey = (in_array($letter,$word_array) ? array_search($letter,$word_array) : ''); for($i=0;$i<=($wordlength-1);$i++){ if (isset($_SESSION["matches"][$matchkey]) && isset($_SESSION["matches"][$i]) && $_SESSION["matches"][$matchkey]==$_SESSION["matches"][$i]){ $_SESSION["matches"][$i]=$_SESSION["matches"][$matchkey]; }elseif($word_array[$i]==$letter){ $_SESSION["matches"][$i]="$letter"; } } $_SESSION["totalGuess"]++; header("location: game.php"); exit; } ksort($_SESSION["matches"]); //style display section $reset=""; $miss_total = $_SESSION["totalGuess"] - count($_SESSION["matches"]); if ($miss_total>={ $color="#ff0000"; $reset="<br />Reset for new game"; }else{ if (count($_SESSION["matches"])==$wordlength){ foreach($word_array as $key => $l){ if ($_SESSION["matches"][$key]!=$word_array[$key]){ $reset="<br />Reset for new game"; $color="#ff0000"; $fail= true; } } $color="#006600"; $reset=(!isset($fail) ? "<br /><span style=\"color:#006600;\">YOU WON</span><br />Reset for new game" : "<br />Reset for new game"); }else{ $color="#000000"; } } //display section $man = "<div style=\"width:100%;\"> <div style=\"margin:10px auto; width:30%;\"> <div style=\"float:left; width:25%; text-align:center;\"> <table border=0 cellpadding=0 cellspacing=0 width=50%> <tr> <td>".($miss_total>=7 ? "<img src=\"images/man7.jpg\" border=\"0\" width=\"15\" height=\"15\" />" : " ")."</td> <td>".($miss_total>=8 ? "<img src=\"images/man8.jpg\" border=\"0\" width=\"15\" height=\"15\" />" : " ")."</td> </tr> <tr> <td>".($miss_total>=5 ? "<img src=\"images/man5.jpg\" border=\"0\" width=\"15\" height=\"15\" />" : " ")."</td> <td>".($miss_total>=6 ? "<img src=\"images/man6.jpg\" border=\"0\" width=\"15\" height=\"15\" />" : " ")."</td> </tr> <tr> <td>".($miss_total>=3 ? "<img src=\"images/man3.jpg\" border=\"0\" width=\"15\" height=\"15\" />" : " ")."</td> <td>".($miss_total>=4 ? "<img src=\"images/man4.jpg\" border=\"0\" width=\"15\" height=\"15\" />" : " ")."</td> </tr> <tr> <td>".($miss_total>=1 ? "<img src=\"images/man1.jpg\" border=\"0\" width=\"15\" height=\"15\" />" : " ")."</td> <td>".($miss_total>=2 ? "<img src=\"images/man2.jpg\" border=\"0\" width=\"15\" height=\"15\" />" : " ")."</td> </tr> </table> </div> <div style=\"float:left; width:50%; text-align:center;\">"; $display = "<span style=\"color:$color; font-size:28px;\">"; for($d=0;$d<=($wordlength-1);$d++){ $display .= (isset($_SESSION["matches"][$d]) ? "{$_SESSION["matches"][$d]}" : "_")." "; } $display .= "</span>.$reset"; //$display .= "</div></div>"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>What's that word</title> </head> <body> <?php echo "$man"; ?> <form action="game.php" method="post" > <?php echo "$display"; ?><br /><br /> <input type="text" name="guessletter" /> <input type="submit" name="guess" value= "נחש"/> <br /><br /> <input type="submit" name="reset" value="יציאה"/> </form> </div> </div> <div style="float:left; width:25%;"></div> </div> </body> </html>
-
Can you make a static grid (table?) of your images? Really the way it is now, ANY missed letter is a fail. So code would need to be changed to use 8 errors to loose.
-
For the fun of it. <?php session_start(); $wordList = array( 'table', 'curtain', 'printer', 'guitar', 'piano', 'dragon', 'pack', 'bottle', 'shirt', 'picture' ); if (!isset($_SESSION['word']) || isset($_POST['reset'])){ $wordkey=array_rand($wordList); $word=$wordList[$wordkey]; $_SESSION['word']=$word; $_SESSION["totalGuess"]=0; $_SESSION["matches"]=array(); }else{ $word=$_SESSION['word']; } $wordlength = strlen($word); $totalGuess = (!isset($_SESSION["totalGuess"])? 0 : $_SESSION["totalGuess"]); //create array of letters in word $word_array = str_split($word); //Check post against word_array if (isset($_POST['guess']) && $totalGuess<=$wordlength){ $letter = trim($_POST['guessletter']); $matchkey = (in_array($letter,$word_array) ? array_search($letter,$word_array) : ''); for($i=0;$i<=($wordlength-1);$i++){ if (isset($_SESSION["matches"][$matchkey]) && isset($_SESSION["matches"][$i]) && $_SESSION["matches"][$matchkey]==$_SESSION["matches"][$i]){ $_SESSION["matches"][$i]=$_SESSION["matches"][$matchkey]; }elseif($word_array[$i]==$letter){ $_SESSION["matches"][$i]="$letter"; } } $_SESSION["totalGuess"]++; header("location: game.php"); exit; } ksort($_SESSION["matches"]); //style display section $reset=""; if ($totalGuess==$wordlength || count($_SESSION["matches"])==$wordlength){ if (count($_SESSION["matches"])==$wordlength){ foreach($word_array as $key => $l){ if ($_SESSION["matches"][$key]!=$word_array[$key]){ $reset="<br />Reset for new game"; $color="#ff0000"; $fail= true; } } $color="#006600"; $reset=(!isset($fail) ? "<br /><span style=\"color:#006600;\">YOU WON</span><br />Reset for new game" : "<br />Reset for new game"); }else{ $color="#ff0000"; $reset="<br />Reset for new game"; } }else{ $color="#000000"; } //display section $display = "<span style=\"color:$color; font-size:28px;\">"; for($d=0;$d<=($wordlength-1);$d++){ $display .= (isset($_SESSION["matches"][$d]) ? "{$_SESSION["matches"][$d]}" : "_")." "; } $display .= "</span>.$reset"; $display .= "<br />$totalGuess out of $wordlength"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>What's that word</title> </head> <body> <center> <form action="game.php" method="post" > <?php echo "$display"; ?><br /><br /> <input type="text" name="guessletter" /> <input type="submit" name="guess" value= "נחש"/> <br /><br /> <input type="submit" name="reset" value="יציאה"/> </form> </center> </body> </html>
-
Does it need the FOR loop? <?php $wordList = array( 'table', 'curtain', 'printer', 'guitar', 'piano', 'dragon', 'pack', 'bottle', 'shirt', 'picture' ); $wordkey=array_rand($wordList); $word=$wordList[$wordkey]; echo "$word"; ?>