Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Hmmm, seems like you guys are going to a LOT more trouble than needed. Just use a simple IF statement in the SQL query. For all users: SELECT *, IF(paid==1,'Paid','Not Paid') as status FROM users ORDER BY last For one user: SELECT *, IF(paid==1,'Paid','Not Paid') as status FROM users WHERE username = '{$session->username}' ORDER BY last
-
Since the numbers are entered in the format 1-2-3-4-5-6 and the '-' is the separator, I don't see how their can be negative numbers. 1-2-3--4-5-6 ??? The OP apparently doesn't wan't to take the time to describe the problen adequately enough to get a solution. I took a second look at the numbers he posted and thought that maybe the numbers were base 5, but even with that there is not a solution.
-
Are you kidding me? Just state what the solutin is for the numbers you used and how you get from number1 to the target number.
-
Please click the link to mark the topic solved.
-
You don't say WHAT is not working with yur str_replace functions, but I will take a guess. 1) They are all commented out. 2) The first line will replace the first value in the $type variable and assign that result to $typename. however the next line will replace the 2nd value IN THE ORIGINAL $type variable (in other words you just lost the replacement on the first line). This continues all the way to the end, so only the last replacement is done. 3) This won't keep it from working, but there's no need to enclose $type in quotes. however, there is a much easier way to do this by using arrays: <?php $codes = array('dailyteenhoroscopes', 'dailyoverview', 'dailyextended', 'dailysingleslove'); $texts = array ('Daily Teen', 'Daily Overview', 'Daily Extended', 'Daily Singles Love'); //I only included four sets, just add all of the strings to these arrays $typename = str_replace($codes, $texts, $type); ?>
-
That's because there is no solution in that list absed upon the criteria you gave! That is why I asked before what the process should be in those cases. It is easy to see that there is no solution. Here are the two input numbers: 1-1-1-4-0-1 1-4-4-4-3-0 Now, since the difference between those two bold numbers is 0, the two modifiers for the solution must have 0 as the fourth number, right? There is only one modifier number in that list of 20 which has a 0 as the 4th digit. So, it would be impossible to add the number1 digits to the digits of two of the modifiers and get the target number digits. Also, how can the last digits go from 1 to 0? That negates the possibility of a solution just with that. If I am not interpreting how this works, them please explain. I built the code according to how I understood the details you provided.
-
Here you go. change the first variable to however many pages you want. I set it at 10 for testing purposes: <?php $page_count = 10; $page = $_GET['page']; if ($page!='Next') { $pages = range(1, $page_count); shuffle($pages); setcookie ('pages', serialize($pages)); echo "You are on the home page. there are $page_count random pages to visit.<br><br>"; echo " Click <a href=\"$_SERVER[php_SELF]?page=Next\">here</a> to start."; } else { $pages = unserialize($_COOKIE['pages']); $this_page = array_shift ($pages); $last_page = (count($pages)>0)?false:true; setcookie ('pages', serialize($pages)); echo "You are on page $this_page.<br><br>"; echo "Pages <span style=\"color:red;\">used</span>/remaining:<br>"; for ($i=1; $i<=$page_count ; $i++) { if (in_array($i, $pages)) { echo "<b>$i</b>, "; } else { echo "<span style=\"color:red;\">$i</span>, "; } } if ($last_page) { echo "<br><br>This is the last page."; } else { echo "<br><br>Go to <a href=\"$_SERVER[php_SELF]?page=Next\">next</a> page."; } echo "<br><br>Go <a href=\"$_SERVER[php_SELF]\">home</a> and start over."; } ?>
-
This appears to work (based upon how I understand the problem). There is a limited amount of verification and I only did a limited amoutn of testing <html> <head></head> <body> <?php if (isset($_POST)) { $modifier = array(); $post_modifiers = $_POST['modifier']; if (is_array($_POST['modifier'])) { foreach ($_POST['modifier'] as $mod) { $mod_ary = explode('-',$mod); if (count($mod_ary)==6) { $modifier[] = $mod_ary; } } } $number1 = explode('-',$_POST['number1']); $target = explode('-',$_POST['target']); //Create an array of the differences. If the result //will be neg, do not add - act as a validation check $diff = array(); for ($i=0; $i<6; $i++) { if ($target[$i]>=$number1[$i]) { $diff[] = $target[$i] - $number1[$i]; } } if (count($modifier)<2 || count($diff)!=6) { echo "<b>Not all required fields entered or correct!</b>"; } else { $soultionFound = false; foreach ($modifier as $modA) { foreach ($modifier as $modB) { if (($modA[0]+$modB[0])==$diff[0] && ($modA[1]+$modB[1])==$diff[1] && ($modA[0]+$modB[2])==$diff[2] && ($modA[3]+$modB[3])==$diff[3] && ($modA[0]+$modB[4])==$diff[4] && ($modA[5]+$modB[5])==$diff[5] && !$soultionFound) { $soultionFound = true; $mod1 = implode('-', $modA); $mod2 = implode('-', $modB); } } } if (!$soultionFound) { echo "<b>No solution found!.</b>"; } } } ?> <form method="POST"> All values should be entered in the format 'n-n-n-n-n-n' (without the quotes): <br><br> Modifier 1: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[0]; ?>" /><br> Modifier 2: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[1]; ?>" /><br> Modifier 3: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[2]; ?>" /><br> Modifier 4: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[3]; ?>" /><br> Modifier 5: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[4]; ?>" /><br> Modifier 6: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[5]; ?>" /><br> Modifier 7: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[6]; ?>" /><br> Modifier 8: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[7]; ?>" /><br> Modifier 9: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[8]; ?>" /><br> Modifier 10: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[9]; ?>" /><br> Modifier 11: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[10]; ?>" /><br> Modifier 12: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[11]; ?>" /><br> Modifier 13: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[12]; ?>" /><br> Modifier 14: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[13]; ?>" /><br> Modifier 15: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[14]; ?>" /><br> Modifier 16: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[15]; ?>" /><br> Modifier 17: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[16]; ?>" /><br> Modifier 18: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[17]; ?>" /><br> Modifier 19: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[18]; ?>" /><br> Modifier 20: <input type="text" name="modifier[]" value="<?php echo $post_modifiers[19]; ?>" /><br> <br><br> Number 1: <input type="text" name="number1" value="<?php echo $_POST['number1']; ?>" /><br> Modifier 1: <input type="text" name="mod1" value="<?php echo $mod1; ?>" readonly /><br> Modifier 2: <input type="text" name="mod2" value="<?php echo $mod2; ?>" readonly /><br> Target Number: <input type="text" name="target" value="<?php echo $_POST['target']; ?>" /><br> <br> <button type="submit">Submit</button> </form> </body> </html>
-
So if a user enters 5-5-5-5-5-5 as Number 1 and 2-2-2-2-2-2 as the Target, how can there be a solution? You cna't add anything to a 5 to make it a 2.
-
There are a few unanswered issues in your explanation: What if there are no combinations of modifiers to make number1 equal the target number? What if there are multiple combnations?
-
@INTPnerd, I understand what you mean. I had similar difficulties when dealing with a language that had very tightly structured arrays for the first time (i.e. had to set the size when creating and changing the size was a chore). But, PHP is much easier IMHO.
-
@thorpe, Nice to see you associating the query with a variable. It is a pet peeve of mine to see people put the actual text of the query within the mysql_query() function and then post questions as to why their query is not working. If they were to assign the query to a variable they could simply write it to the screen to see what the error is.
-
I really don't know what you are really asking. The PHP code is nearly identical to the C# code, so why are you unsure "what" is happening in the PHP code. The first line declares a new array object (you do not need to assign a size to the array - it is just an empty array). The loop then itterates from 0 to 99 and creates an item int he array and assigns a value to it in one step.
-
You can't "really" share a cookie across multiple domains - only sub-domains. According to this page http://www.15seconds.com/issue/971108.htm (which is about ASP, but the logic is valid for PHP), making a COOKIE available across domains is more of a "trick" than a function. The first domain will issue the cookie, and the second domain will request the cookie from the first. However, you need to be VERY careful here. If you don't put up proper security, then a 3rd party site could access cookies from your site. Just make sure any requests are from your domains.
-
Although your solution was not as eloquent, it made up for it in being more flexible. That was a great idea to make it variable for the DOW that you are trying to find. I have updated my one-liner to take advantage of that and added it to my library: <?php //############################################## // // Function: GetDOWDate($date, $dow) // // Description: // This funtion takes a date (timestamp) and // a DOW (day of week 0-6) and returns the // timestamp for the DOW in the input date // // Parameters: // - date: Timestamp for the source date // - dow: The Day of Week to return // //############################################## function GetDOWDate($date, $dow){ return ($date - ((date('w',$date)-$dow)*60*60*24)); } $currentDate = mktime(); //Today's date $DOWtoReturn = 2; //(0-6, Sun-Sat) echo date('l, m-d-Y', GetDOWDate($currentDate, $DOWtoReturn)); ?>
-
I think you forgot to change one of your variable names. "current_date" shoudl be the same variable as $date within the formula: <?php function GetMondayDateForWork($date){ return ($date - ((date('w',$date)-1)*60*60*24)); } ?>
-
[SOLVED] find value in array depending on word in user input
Psycho replied to helraizer's topic in PHP Coding Help
The code below will only work "well" if there is only 1 bad word in the text. There are different ways to handle if there are multiple bad words and I didn't want to make an assumption. <?php define('_SWEAR', 'The word you entered, [WORD], has been detected as being offensive; your post has not been submitted. Sorry for any inconvenience.'); //for the error. $dirty = array('rude word', 'another', 'and another rude word', 'another, please Carol'); $error = false; foreach($dirty AS $bad_word){ if (strpos($text, $bad_word)) { $error = preg_replace("/[WORD]/", $bad_word, _SWEAR); } } if ($error) { echo $error; } else { //Process the post } ?> -
Forgive me, but why the hell do you have all those elseif statements? You're making the problem much harder than it should be. You also have a problem in that you are setting $ammount1 to $ammount. For "otherammount" that will result in a string value instead of a numeric value (in the current code). <?php $name = substr($_POST['name'], 0, 65); $address = substr($_POST['address'], 0, 300); $email = substr($_POST['email'], 0, 65); $phone = substr($_POST['phone'], 0, 65); $ammount = substr($_POST['ammount'], 0, 65); $otheramount = substr($_POST['otheramount'], 0, 65); $receipt = substr($_POST['receipt'], 0, 65); $dontcall = substr($_POST['dontcall'], 0, 65); if ($ammount == "otheram") { $ammount = $otherammount; } if (is_numeric($ammount)) { //Send the email $to = "test@test.com"; $subject = "Donation Confirmation"; $from = "test@test.com"; $headers = "From: $from"; $body = "Donation Successful for $ammount dollars"; mail($to, $subject, $body, $headers); //Redirect to paypal $paypal_loc = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick"; $paypal_loc += "&business=holloway%2eian%40gmail%2ecom&item_name=Donation"; $paypal_loc += "&amount=$ammount1&no_shipping=0&no_note=1¤cy_code=USD"; $paypal_loc += "&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8" header("location:$paypal_loc"); } else { // Value is not a number need to add error condition here } ?>
-
Don't use the php short tags they are not supported on all servers. Also the FONT tag has been depricated for many years, use styles. this should do what you are asking for: <?php // generate and execute query $query = "SELECT id, title, timestamp FROM blog ORDER BY timestamp DESC LIMIT 0, 4"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); if (mysql_num_rows($result) > 0) { // records present // iterate through resultset // print article titles while($row = mysql_fetch_object($result)) { $span_style = ($row->id==$id) ? ' style="background-color:#FFFF00;"' : ''; echo "<li><a href=\"blog.php?id={$row->id}\">"; echo "<span {$span_style}>{$row->slug}</span><em>".formatDate($row->timestamp)."</em>"; echo "</a></li>"; } } else { // no records present // display message echo "<font size=\"-1\">No Blog Entry currently available</font>"; } // close database connection mysql_close($connection); ?>
-
Your query is not very clear, it would be VERY helpful if you provided the two queries you are currently using to generate those two lists. I would look for a solution to modify the query of the list you want to use the highlighting in to add an additional column to identify if it should be highlighted or not.
-
[SOLVED] Having problem adding value to associative array
Psycho replied to kjtocool's topic in PHP Coding Help
No, you do not have a nested array. from the looks of it, your results are what you want. The problem is that you are using print_r() on each loop. So, on the first itteration of the loop you have: Array ( [2] => 58.038 ) On the second itteration of the loop you get the first item and the second item: Array ( [2] => 58.038 [11] => 55.99 ) On the 3rd itteration you get the first 2 items and the 3rd item: Array ( [2] => 58.038 [11] => 55.99 [33] => 84.26 ) And so on... So, just move your print_r() so it comes after the foreach loop and you should see that the array is exactly how you want it to be. -
<?php $query = mysql_query("SELECT `post_subject`, post_text FROM `phpbb_posts` WHERE `forum_id` = 2 ORDER by `post_id` DESC LIMIT 2"); $article1 = mysql_fetch_assoc($query); $article2 = mysql_fetch_assoc($query); ?>
-
Well a quick Google search brought up many. here is one: http://calendar.swazz.org/