Jump to content

Search the Community

Showing results for tags 'if'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 24 results

  1. Hi, Freaks. I've got a quick question I'd like to ask out of curiosity I coded a simple pagination functionality last night. It's nothing intricate. The page it's for pulls a large amount of data and is displayed 10 rows at a time. To determine which data to display it uses a simple $_Get['from'] and $_GET['to']. They start out as $from = 0; and $to = 10; and are each incremented or decremented by 10 if the user clicks 'prev' or 'next'. I got it functioning properly and then needed a quick if statement to disable the 'prev' if $from == 0 && $to == 9; (so it didn't go to -10 and -1 respectively and break the script). This was the original try -> <?php if($from == 0 && $to == 9) { $state = "disabled"; } else { $state = "active"; } $html = sprintf("<a href='/qcic/newsnet/pages/%s.php?act_id=%s&act_title=%s&from=%s&to=%s' class='%s'><i class='fa fa-angle-left'></i> previous</a>", $actor, $id, $actor, ($from-10), ($to-10), $state); echo $html; And it did not work. $from became -10, $to became -1 and it broke the script. I changed it to this -> <?php if($from == 0 && $to == 9) { $state = "disabled"; $html = sprintf("<a href='#' class='%s'><i class='fa fa-angle-left'></i> previous</a>", $actor, $id, $actor, ($from-10), ($to-10), $state); } else { $state = "active"; $html = sprintf("<a href='/qcic/newsnet/pages/%s.php?act_id=%s&act_title=%s&from=%s&to=%s' class='%s'><i class='fa fa-angle-left'></i> previous</a>", $actor, $id, $actor, ($from-10), ($to-10), $state); } echo $html; This way worked So I have 2 simple questions regarding this: 1. Why didn't the first method work and I had to make the $html variable twice and actually remove the URL? and 2. How would I provide the same functionality to the 'next' button with an undetermined amount of data? - i don't know how many entries there may be, but when the script gets there I want it to know it got there and act accordingly. Can I get open thoughts on ways to achieve this? TIA and the best of Sundays to all you freaky geeks
  2. Hi guys, I have this script I am running, http://pastebin.com/NR1A03hY, works perfectly and does everything I need it to do. The only thing is the redirect at the bottom of the script does not work if line 40 is true. I think I have a problem with my foreach loop and the if statements in-between. Please can someone check, I have no idea on this one! Edit: in the pastebin the redirect is striked out as i was problem solving it. Of course i would not strike it out once its back working! Thanks
  3. Trying to simplify my code to something like: if($_SESSION['url'] != 'http://www.golden-wand.com/Pages/admin.php'||'http://www.golden-wand.com/Pages/admin-test.php') This is what works that I would like simplified: <!---------------------------------- ADMIN FUNCTIONS START -------------------------------> <?php if($_SESSION['admin']=='1'){ if($_SESSION['url'] != 'http://www.golden-wand.com/Pages/admin.php'){ if($_SESSION['url'] != 'http://www.golden-wand.com/Pages/admin-test.php'){ ?> <input type="button" value="Admin Page" class="button hvr-wobble-skew" onclick="location.href='http://www.golden-wand.com/Pages/admin.php'"> <?php }}} ?> <!----------------------------------- ADMIN FUNCTIONS END -------------------------------->
  4. HI Guys, Newbie question Can anybody help me with what is wrong with my IF Statement Please: <td>if ($record['docs_available'] = "1"){ echo ".$record['status_name'].";} else {echo ".$record['docs_available'].";} </td thanks in advance
  5. Hi all, Sorry if this isnt the right place to ask this. I have tried many other forums and have had no luck. I am learning programming for Raspberry Pi. Currently, I can read the output of a pin (GPIO) on the circuit board as such: <?php exec ( "gpio read 7", $status ); print_r ( $status ); ?> That works fine - it prints the status to the screen. However, if I put this in an 'if' statement, eg: <?php if (isset($_GET['trigger']) && $_GET['trigger'] == 1) { exec ( "gpio read 7", $status ); print_r ( $status ); exec ( "gpio write 7 1" ); } ?> It no longer works. I know the if statement is correct as exec ( "gpio write 7 1" ); produces results. Would anyone know what I have done wrong here or why I would not be able to read the status? Many thanks in advance
  6. HI, I am a beginner at programing and I have to do this project where it is asking me to validate any ISBN 13 number. I know how to set up the input page, but I am having or you could say no Idea how to validate a number if user inputs data in the input page. I have some could below that I think it should be included, but if someone has better way to do it then I would be appreciate it. here is the input page code: <form method="POST" action="Process_isbn13.php"> <p>Enter the ISBN 13: <input type="text" name="isbn13"/></p> <input type="submit" name="Submit" value="Submit" /> </form> I have this so far for my processing page to validate the ISBN 13 number! <?php function isValidISBN13($isbn) { $sum = 0; for ($i = 0; $i < 13; $i++) { if ($isbn[$i] === 'X') { $value = 13; } else { $value = $isbn[$i]; } $sum += ($i + 1) * $value; } } ?> I know there should be more like if it is empty it should say it's empty do it again and if it is not validate then it would say that. The most important thing I need is the code so if i enter a validate ISBN 13 number it would say it's validate! Someone please help me with the code needed to check if ISBN 13 number is validate.
  7. I'm a PHP beginner - I'm not sure what is wrong with this code. The problem: When $qotw is equal to 1 or when it is equal to 2, neither statement is being executed (see code below). I am not getting any errors. What I tried: I tried putting if($qotw = '1') instead of if(qotw == '1') and if(qotw = '2') instead of if(qotw == '2'). In that case the 'cash' increased as it was supposed to. However, when $qotw was equal to 2, the first statement still executed and the second one did not (the 'cash' value was still increasing and the message that should be displayed according to the 2nd IF statement did not show up). The 'cash' value and 'qotw' value should only increase when $qotw is equal to 1. Please help me fix this so that BOTH statements will execute at the appropriate times. Thanks! Here is my code: <?php $con=mysqli_connect("localhost","users","password","users"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } //statement1 if($qotw = '1') { mysqli_query($con,"UPDATE users SET cash = cash + $scash WHERE username = '". $_SESSION['username'] . "'"); mysqli_query($con,"UPDATE users SET qotw = 1 + qotw WHERE username = '". $_SESSION['username'] . "'"); } //statement2 if($qotw = '2') { echo "You have already attempted this question."; } mysqli_close($con); ?>
  8. Got a question. Hope not worked with PHP too long so, I'm trying to print/echo the date but I don't understand what the hell the date is that it's sourcing. My code is; <!DOCTYPE html> <html> <head></head> <body> <?php $t=date("H"); if ($t<"15") { print "Have a good Morning"; } else if ($t<"17") { print("Have a good Evening"); } else print("Have a good Night"); ?> </body> </html> But it's producing each answer randomly in my browser because I don't know what 'Date' it supposedly is. Any enlightenment to this would be much appreciated. Basically, I've written, if ($t<"15") { print "Have a good Morning"; } So what date is this '15' ? It's not day of the month and it isn't year or time. Help
  9. Some of the search results have snippets and some do not so I need an if statement inserted for the cases there aren't any. Seems that when I try to insert an if statement it gets picked up as html. What would be the best way to insert an if here? $Blekko = array ("<a href=\"{$item->url}\"> {$item->url_title}</a> <p> {if (snippet == '') { $item->'No snippet' } $item->snippet}</p>") }
  10. I am writting a document management application which is running a very large if statement, similar to if(($filetype == jpeg)||(filetype == gif)){ $type = "Image"; }elseif... and so on it's about 180 lines. The Problem is I can do it in an array as well, an array will be less code. but is it faster? I am talking large amounts my software knows 600 different extensions with 380 different icons assigned to the file type. I need to know for performance which is faster? and array or an if and ifelse? If I could get assistance that would be good. I would test it myself but rewritting as array for no reason if an if statement is the faster of the two. Thanks.
  11. The first block of code is what i want to use since i know it works, but i dont know how to use it with the code already there. <?php if (strpos($_SERVER['REQUEST_URI'], 'upload.php') == false) { echo 'the stuff below is removed, or if the URL is something else, its not removed' ?> This code is already in my form and can not be changed!!! This is what I want to remove totally if the URL is upload.php <div class="navbar" name"navbar" Id="navbar"> <div class="navbar-inner" name="navbar-inner" Id="navbar-inner">' <?php echo a_view('core/account/login_dropdown'); ?> <?php echo a_view_menu('topbar', array('sort_by' => 'priority', array('menu-hz'))); ?> <?php echo a_view('search/search_box', array('class' => 'search-header')); ?> </div> </div> Can anyone help?
  12. I need a list for a form that will be used to register children to their legal guardian. The list is a drop down menu, which will eventually be sorted alphabetically, if php can do that . However, the current problem is that there are single parents out there, way current way the code is set up works, but it looks off when there is a random '&' with no second parent name. When I try to do a ternary operation, it completely stops all options from appearing from the drop down. Here is the code that WORKS: echo "<option value=" . $row_list["parentID"] . ">" . $row_list["parentOneFirstName"] . " " . $row_list["parentOneLastName"] . " & " . $row_list["parentTwoFirstName"] . " " . $row_list["parentTwoLastName"] . "</option>"; Here is the code with the ternary operation: echo "<option value=" . $row_list["parentID"] . ">" . $row_list["parentOneFirstName"] . " " . $row_list["parentOneLastName"] . ((!empty($row_list["parentTwoFirstName"])) and (!empty($row_list["parentTwoLastName"]))) ? " & " . $row_list["parentTwoFirstName"] . " " . $row_list["parentTwoLastName"] . "</option>" : "</option>"; Anyone know what the problem is, or even better, how to fix it? I appreciate any and all input, thank you.
  13. <?php $noError = 0; echo"Test 1 Passed</br>"; ?> <?php include 'f2.php';?> <?php echo"Test 2 Passed</br>"; if($noError = 0) { echo"Test 3 Passed"; } ?>
  14. Hello guys, I have a slight problem with a booking form i made. Booking form is for minicab booking so price calculation is involved. The booking form was working fine with php4 enabled hosting but i have problem with php5 hosting. Script doesnt pass the varible after if conditions are mathced. What happens is, when user selects a pick up address and dropp of address, price should be set in $quotation. The code is below; if ($postcode == "AL1 St. Albans" && $airport == "Heathrow T1" ) { $quotation = 42;} where you see 42 is how much the journey will cost but it doesnt reflect on the final page. I have also tried the following code which works fine; if ($postcode == "AL1 St. Albans" && $airport == "Heathrow T1" ) { echo "42";} Can anyone help me solve this error. Thanks
  15. Hello I'm new in this forum but i hope you understand what I trying to do. <?php $theanswer = 4; $answer = $_POST['answer']; if(isset($_POST['button'])){ if ($theanswer = $answer){ echo "Right the answer is 4<br>"; } else { echo "Wrong try again!"; } } ?> 2 + 2 is? <form method="post" action="new.php"> <input type="text" name="answer"> <input type="submit" name="button"> </form> The code don't work and I get an notice too. Notice: Undefined index: answer in C:\wamp\www\ss\new.php on line 4 I think you understand what i want but i will explain if you don't. If they write 4 in the textfield the echo will say Right the answer is 4. But if they write anything else it will say wrong try again! Now i wonder what have i do wrong?
  16. So I'm just learning PHP and MySQL for the first time, and I've been doing really well. I have a lot of experience with HTML and C++ so a lot of concepts are very familiar. I'm currently using if { to determine whether or not an HTML form field has any data in it or not. If either of two fields are empty, it echoes a warning to the user and re-prints the form on the resulting page. Here's a link to a pastebin of what I currently have. Note that I have tried $form_output both as 'true' and 'false' & also just as plain true and false (no quotes). Both seem to fail when I reach the if statements. Even if the $subject or $body variables are false, it still starts sending the emails in the if ($output_form = false) section. So my question is partially - does PHP recognize true and false without quotes as boolean variables? Or does it just think they are plain text? I figured that because they have no quotes, if it didn't recognize them as special terms it would crash the script at that point. I need to learn how to use a PHP debugger on Linux, so if someone could help me with that too, that'd be great. I probably wouldn't even have to ask this question because the debugger would have shown me what the script is actually doing. My other question is, the book I'm learning from shows the script going in and out of the <php? tags, back to HTML, then back into <php? to close the script (at the bottom of the above link). Is that accepted syntax or is that incorrect? Thanks a lot in advance for your help!! Much appreciated.
  17. Hi everyone ! I'm new here... So I got a little problem with creating my first website. I want to include files with the content of my subpages to the main index file. At the first I made a simple solution with switch. Where the urls to the files in the menu look like: href="index.php?page=1" than "page=2" and so on and the code in the place of subpages content was: <? switch ($_GET['page']) { case 2: include("/subpages/aboutme.php"); break; case 3: include("/subpages/a=gallery.php"); break; case 4: include("/subpages/movies.php"); break; case 5: include("/subpages/contact.php"); break; case 1: default: include("/subpages/main.php"); } ?> Of course this solution was correct and it was working BUT what about when someone change the url to the ..."index.php?page=10000000" just because being curious and to check what will happen (there isn't any site with the sign "The page you're looking for cannot be found") and the other reason why I want to upgrade my include solution was that I have to add another cases every time when I want to make another subpages. So I decided to change it and my new url code in menu looks like: href="index.php?page=aboutme" or href="index.php?page=gallery" (so after equal sign there is an exactly name of my subpage without ".php") and than the code which includes my content is: if (file_exists('subpages/' . $page . '.php')) { require('subpages/' . $page . '.php'); } else { echo '<div id="main"><span>The page you’re looking for cannot be found.</span></div>'; } where the $page=$_GET['page']; It is working too but only when I click on one of the subpages in my menu but what about default like in the switch solution? I mean the case when I go to my site typing url without selecting any subpage. Now there is just the sign "The page you're looking for cannot be found." My other question is that I want to add a guestbook which is in the other folder in subpages so the url is "subpages/guestbook/gbook.php". What should I change in my code which works only for the subpages folder? I try to do something like this but it doesn't work: if ($page='gbook' && file_exists('subpages/guestbook/' . $page . '.php')) { require('subpages/guestbook/' . $page . '.php'); } elseif ($page!='gbook' && file_exists('subpages/' . $page . '.php')) { require("subpages/' . $page . '.php'); } else { echo '<div id="main"><span>The page you’re looking for cannot be found.</span></div>'; } Sorry for the length of this topic but I want to avoid unnecessary questions and useless solutions and I want apologies for my English but I'm 17 and I'm from Poland so I've been still learning it !
  18. If ($Hoff == 'Nelspruit') || ($Hoff == 'Hoedspruit') || ($Hoff == 'Klaserie') || ($Hoff == 'Bushbuck Ridge') || ($Hoff == 'Hazyview') || ($Hoff == 'Graskop') OR ($Hoff == 'Sabie') || ($Hoff == 'Lydenburg') || ($Hoff == 'Pilgrims Rest') || ($Hoff == 'Barberton') || ($Hoff == 'Waterval Boven') || ($Hoff == 'Komatipoort') || ($Hoff == 'Malelane') { $addon = $addon +2; } else { $addon = $addon -100; } PHP Parse error: syntax error, unexpected '||' (T_BOOLEAN_OR) in /home/lowveldn/public_html/control/publish.php on line 84 Can someone tell me what is wrong here please.
  19. Hi, I am working on a PHP file and need it to open a URL and if there is a certain word or phrase on the web page then open a second URL. If the text is not there, then I need the first URL to continually open until the text is found. I would imagine this is pretty simple, something like an IF statement and a loop somewhere. But how do I do this? Any help would be greatly appreciated!
  20. Hello All, First let me say, happy holidays! Second, I am glad to see that you are all still here. I am having trouble passing a variable through the url, getting it and then determining the correct query with it. For example: $find = $_GET['x']; if ($find = 'y') { sql = "SELECT * FROM table1"; } if ($find = 'z') { sql = "SELECT * FROM table2"; } mysql_query($sql, $connection); When I do this and then change the variable in the url it just takes the information from the first if statement. $find if always equal to "y". Any ideas??
  21. Hi all, i am fairly new with php and i am running into a problem with a php function. It is very basic but i've got something wrong here. It is a function in wordpress that needs to analyze the post and extract the category. For every category another value needs to be returned. My code is: function postimage($post_id){ $category = get_the_category( $post_id ); $id = $category[0]->cat_ID; if ( $id = 45 ){ $link = 'This is category 45'; } else { $link = 'This is not category 45 '; } return $link; } There are 2 strange things happening: 1. The first statement is always true. Even if the category id is not 45 it still returns the first $link. 2. If i return the variable $id after the if statement it returns als 45. If i do it without the if statement it returns correct. The 2 problems are obviously related but i don't understand what i'm doing wrong. Please help
  22. Hi folks, relative newbie so my code wont be pretty, however... This one has me stumped. I have written some PHP to change the background colour of a cell in a table based on a variable. The code is as follows: // Convert Summer 8 Grade to a number value if ($row['Sum8']=='1a') { $sum8_value=3; } elseif ($row['Sum8']=='1b') { $sum8_value=2; } elseif ($row['Sum8']=='1c') { $sum8_value=1; } elseif ($row['Sum8']=='2a') { $sum8_value=6; } elseif ($row['Sum8']=='2b') { $sum8_value=5; } elseif ($row['Sum8']=='2c') { $sum8_value=4; } elseif ($row['Sum8']=='3a') { $sum8_value=9; } elseif ($row['Sum8']=='3b') { $sum8_value=8; } elseif ($row['Sum8']=='3c') { $sum8_value=7; } elseif ($row['Sum8']=='4a') { $sum8_value=12; } elseif ($row['Sum8']=='4b') { $sum8_value=11; } elseif ($row['Sum8']=='4c') { $sum8_value=10; } elseif ($row['Sum8']=='5a') { $sum8_value=15; } elseif ($row['Sum8']=='5b') { $sum8_value=14; } elseif ($row['Sum8']=='5c') { $sum8_value=13; } elseif ($row['Sum8']=='6a') { $sum8_value=18; } elseif ($row['Sum8']=='6b') { $sum8_value=17; } elseif ($row['Sum8']=='6c') { $sum8_value=16; } elseif ($row['Sum8']=='7a') { $sum8_value=21; } elseif ($row['Sum8']=='7b') { $sum8_value=20; } elseif ($row['Sum8']=='7c') { $sum8_value=19; } elseif ($row['Sum8']=='N') { $sum8_value=0; } elseif ($row['Sum8']=='X') { $sum8_value=25; } elseif ($row['Sum8']=='B') { $sum8_value=5; } elseif ($row['Sum8']=='-') { $sum8_value=150; } // Calculate progress for Summer 8 $sum8_progress = number_format(($ks3_target_value-$ks2_value)*0.75)+$ks2_value; $sum8_progress_final = $sum8_value-$sum8_progress; if ($sum8_progress_final< -1) { $progress_colour_sum8="#ac3845";} elseif ($sum8_progress_final==-1) { $progress_colour_sum8="#c5a751";} elseif ($sum8_progress_final==0) { $progress_colour_sum8="#93a336";} elseif ($sum8_progress_final>= 1 && $sum8_progress_final<= 34) { $progress_colour_sum8="#477dae";} elseif ($sum8_progress_final>= 35) { $progress_colour_sum8=$row_color; } If you can follow my code, the problem is that currently $sum8 = '-' for every entry in the table and therefore working everything through the cell should end up being $row_color which is basically grey. However it is showing up as #477dae This code works on every other column in my table (the only difference being sum8 is spr8, aut8, sum7, spr7 etc etc (for autumn, spring, summer year 7, 8, 9 etc etc. It is only the sum8 based column that does not work. I have echo'd the results to check and find the following: $sum8_progress_final is in the 100's for every result $progress_colour_sum8 however is #477dae for every result? Any suggestions or thoughts?
  23. Hello All, If I have a newsletter process script with name and email, is there a way to identify if the email is an email address? For example johndoe@gmail.com. I kind of want to think of a way to identify if it is a real name as well. Maybe just ask for first and last name. Thanks,
  24. Hi I am currenly doing a project where i am required to send some values to secure http via post request..I am using Curl for this and that works fine, what I am stuck on is how to retrieve stored database values and send each one individually in a loop to the specified url in the curl script. Hard to explain but heres an example: e.g I have a number of reports in db (123456, 123654, 456321) and each one will retrieve a report from the url as they are the specified report_ids required. I would like to pull each one from the database using a foreach loop assigning the report number to $reportid variable one at a time, and also when the report is retrieved with each one, fwrite it to file. I can currently get all of the above working but only if i assign the report number in the script rather than assigning it the db value and looping through each one. I suppose my question is how can i not only loop through db values but assign each id to the reportid sent via curl and then do it all over again for the next id... Any help in the right direction would be awesome.!
×
×
  • 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.