Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Question On Conditional Statements


I'm a perl programmer and am trying to learn PHP.

So far I have figured out most of the differences, but have not been able to
find out how to do the following:

When running through a loop, how can you test two separate conditions
against the same $element of an array. For example, this is how I thought it
would be done (similar to Perl), but it did not work:

if (eregi("apple", $line) and (eregi("orange", $line) {

do whatever;

}

Basically testing each line of an array to see if both the words "apple" and
"orange" are present.

Also, is there any equivalent to the following from Perl while running
through a loop:

next if (whatever conditions);
last if (whatever conditions);




View Complete Forum Thread with Replies

Related Forum Messages:
Conditional Statements And Loops
Not long ago I was asked to give PHP lections to some private IT
school. I'm on second lection now, and will be teaching my :) students
conditional statements (if..else and switch) and loops (while and for).
That was my story, now the question.

Can you give me an advise on some geeky use of those statements to stir
up some enthusiasm in students.

View Replies !
Avoiding Endless Conditional Statements
Here is my problem. I want to make a webapp that will basically take
the work out of finding what tool works for what situation. There are
5 factors that go into tool selection. 1)Material Group, 2)Insert
Radius, 3)Insert Type and Size, and 2 others that I can't remember
off-hand. There are probably about 1000 different scenarios that I
have to code for..(there are several blank table cells and it's not
setup as you might imagine, there is a lot of overlapping), and I
desperately want to avoid making a gigantic conditional statement. I'm
afraid that I really have to provide a picture of what I'm doing here,
so I will do that. Here is the link.
You only see 3 of the 5
factors on this page, and the other 2 have to do with whether this
table or one of many other tables (not pictured) will be used.

So, now that I've confused everyone. That's my table. What's a good
way to go about programming that sucker in so that people don't have to
do all the "work" involved to figure out what tools they need. They
should just be able to choose selections from 5 dropdown boxes and get
one tool back. A tool is something like "10.655.600".

View Replies !
Mysql Real Escape String() In Conditional Statements
I created the following bit of code that allows me to pass a MySQL conditional statement to a function.

I am trying to figure out where and how would I go about incorporating the mysql_real_escape_string() function?

Is there a way to call the mysql_real_escape_string() in the function itself? Code:

View Replies !
Possible To Include Conditional IF Statements Inside Switch Case Declarations?
Is it possible to include conditional IF statements inside switch case declarations?

For example... Instead of doing...

View Replies !
Conditional
I am having an issue here that no matter what happens, my else statement is always displayed with my if! Can someone help me, I can't seem to find where I messed up. PHP Code:

if ($_GET['cat'] == "wired") {
    $f_p = "iframe_wired.php";
    echo "<iframe src="$f_p" name="$f_n" scrolling="$f_s" frameborder="$f_b" align="$f_a" height="$f_h" width="$f_w">
    </iframe>";
} else {
    exit();
}

    if ($_GET['cat'] == "wireless") {
        $f_p = "iframe_wireless.php";
        echo "<iframe src="$f_p" name="$f_n" scrolling="$f_s" frameborder="$f_b" align="$f_a" height="$f_h" width="$f_w">
..........................

View Replies !
Conditional Loop
I have one table, "players" that has player info including start season (year). I then have a table for each season with player stats, i.e. games played etc called stats200X where X is the year obviously.

I have no problem with extracting data from the current year, but what I would like to do is get data from previous years too. I was thinking about doing something like:

(year) - (startyear), which for example could be 3.

I don't know where to begin, but I want to be able to loop though previous years so that, if tables exist of course, I could do

select * from stats{Y -1}
display
select * from stats{Y -2}
etc

Would I need to hard code this or is there a way of doing this though a conditional loop?


View Replies !
Conditional Login..
I have a form with a username & password field along with 3 radio buttons.

What I basically want to achieve is if radio button A is checked it will post the username & pass to a.php, If button B is checked it will post the username & pass to b.php and so on for button C.

View Replies !
Checkboxes,conditional
Basically I have what seems to be a very small problem but I am driving ny self mad trying to figure out what the problem is. Here is what I have: I have a form with two checkboxes:

<input type="checkbox" name="medicalcheck" >
<input type="checkbox" name="dentalcheck" >

the form is posting the a php file, decision.php, that simple checks to see if the boxes have been checked and performs an operation in either case. Here is the code:

View Replies !
Once Conditional Causes Error, The Other Doesn't...why?
There are 2 if statements at the beginning of this code snippet.  The one that is currently commented out works while the one that is not commented out yields this error

Parse error: syntax error, unexpected '{' in C:xampphtdocsench2index4.php on line 106

I am just not seeing why. Code:

View Replies !
Conditional Structures
I am wondering about conditional structures and the depth of nesting allowed, if at all. For example I know I can do this: Code:

View Replies !
Conditional Form
I want to condtionally display an HTML form. I havnt got a clue how it can be done, I suppose its the same way as putting html tables in php, but I cant get it to work. Here is the condtion:

<?php 
 if (!empty($pk))
  {    

And here is the form:

<form action="google.php" method="GET" name="deleteForm" >
<input type="hidden" name="pk" value="<? echo $pk;?>">
<input type="submit" value="Delete">
</form>

View Replies !
PHP Conditional Include
I just set up a perl script that outputs a single html file. Works great, but I need to be able to customize that one file for different sections of the site. Specifically I need different navigation and heading on the page.

I'm not a programmer, but this sounds like I want a conditional include to show what I want when I want, right? If so, can anyone give me any idea how to get started with something like this? I figured I'd try with PHP because it sounds easier than fooling with perl.

Also, doesn't a conditional statement generally work from a variable or something else in the page that changes? If so, what do I do when the page stays the same and doesn't include variables?

View Replies !
Include In Conditional
Why does this not work?

if (!$artnr) {
include "./smalltable.php";
}
else {
include "./bigtable.php";
}

Is this the best php group for this sort of question?

View Replies !
If/Else Conditional Statment
I just started php yesterday and found a site with a good tutorial but there's a problem, the "If/Else" statment doesn't seem to work, don't know if it's wrong in the tutorial or what. Code:

View Replies !
Conditional Redirection
I understand the header thing but wanna redirect to different pages based on values entered on the previous page.

View Replies !
OR Conditional Statement
I am trying to do this. But for some reason or does not work. How do you do an or statement with PHP?

if ($var == 8 or $var == 9) {
print "is eight or nine";
} else {
print "not eight or nine";
}

View Replies !
More Than 1 Conditional In A Function
This is a great function I use to echo timestamps as "how long ago" timeframe. This function rounds up the time to the smallest hour, so that 2:55 echos "2 hours ago". The only conditional in this function is Code:

if($difference != 1) $periods[$j].= "s";
and what it does is to add an "s" if the second, minute, hour... is not 1 (pluralization).

I need now to add another conditional so that for anytime greater than 5 hours and less than 24 hours it will echo just the word "Today". I tried many possibilities without much success. Code:

View Replies !
Conditional Against A Variable
what is wrong with this statement? The $ session is defined on the page. $session;

if($row_test['P_ID'] = $session){echo'show value'}
elseif($row_test['P_ID'] <> $session){echo'do not value'}

View Replies !
Conditional Submit
I'm creating a subscription form and i like to know how to create an interactive submit button. What i want is a submit button which only can be used when they agree with the terms of conditions by checking a checkbox.

View Replies !
Conditional Expression
I am trying to list products that are greater than $100 and less than $250. Yet the expression isn't working.

if ( $price >= "$100" ) && ( $price <= "$250" ) echo "$item<br> "; else echo " ";

Obviously if I set my query to

$query = "SELECT * FROM products WHERE price > '$100' AND price < '$250' ORDER BY id ASC";

it works.

View Replies !
Conditional Echoes
I need to place all this within the the echo, but get nothing but a blank page when doing so. (so this only shows when values are present.) Code:

View Replies !
Conditional Processing
imagine i have the following code PHP Code:

if($var == 12)
{
echo 'blah'
echo 'blah'
echo 'blah'
echo 'blah'
echo 'blah'
echo 'blah'
echo 'blah'
echo 'blah'
echo 'blah'
echo 'blah'
}
else
{
echo 'blah'
}

lets imagine that if $var is 12 the page takes 5 seconds to load. if $var isnt 12 will the page still take 5 seconds to load? I need to know if the unused code in conditionals are still processed, or maybe processed before the conditionals.

View Replies !
Conditional Formating
im working with a calendar script called phpicalendar, my install is here. I'm trying to get the cell background to change according to the text in the days event.

ie different class for cell bg I have figured out how to change the html in the template but im not sure how to carry this accross. Code:

View Replies !
Conditional Statement
I have made pages to create databases and the db gets created, but if i specify a not null auto_increment ,primary key the script ignores it and just makes the column a int column. Code:

View Replies !
Perform Conditional
I'd like to check these two conditions:

if ((is_page() or ($category->cat_ID === $cat)){
do something
}

but keep getting an "unexpected {..." error. If I do this, it works fine:

if ($category->cat_ID === $cat){
do something
}


View Replies !
Conditional Onclick
<input type=button value="<?php echo $button_caption ?>" onclick="if (verifyChange() == true) {location.href=$_SERVER['PHP_SELF'].'?homeinclude=member&pageaction=signupok'}">

I get the "missing name after . operator" error.

View Replies !
Conditional Third Expression In For Loop
Is it possible to make expr3 $i++ under one condition and $i-- under another? Instead of having the condition outside the loop and having two loops. Or I could just use a while loop, I guess.

View Replies !
Sessions + Conditional Include
I am having a little problem in trying to figure out why my session state is not expiring after I close the browser window. Having been used to the ASP way of doing things I am trying to get my head around this slightly different method of handling sessions in PHP....

What happens is that I log on to the site, do various things and then close it when I am finished. I return the next day to find that the 'logged in' menu is displayed first which shouldnt happen until you have logged in again.

I assumed that the session was been stored as a cookie but wasnt been released after the session terminates by default, but found I was wrong when I deleted all my internet files and went back to the site.

My code for the first page is as follows..

View Replies !
Conditional PHP Cookies; If Cookie = 1 Do This...
I've figured out cookies ... now I'm trying to combine them with if conditions.

For cookie 'bandwidth1' I want to echo that it is set to 1 by the cookie to confirm this in the brower through regular html.

My if/else statements don't seem to be working though...heres the code I have now.

<?php
setcookie("bandwidth1","0",time()+2592000,"/");
setcookie("bandwidth2","1",time()+2592000,"/");
setcookie("bandwidth3","2",time()+2592000,"/");
?>

<?php
if (isset($_COOKIE["bandwidth1"])=="1")
echo "Bandwidth is 1!";
else
echo "Bandwidth is unknown";
elsif
echo "Cookie was not set?";
?>

View Replies !
MySQL Conditional Statement
What I am trying to do is kind of like an advanced search. Basically, I have three dropdowns, for this I am going to use the example books: Three dropdowns, which are

1) Author
2) Language
3) Type (Hardback or Paperback)

Typical search: I want to get a list of all books written by STEPHEN KING, that are written in ENGLISH and that are HARDBACK ok fine, but what if I just want to search for ALL books by STEPHEN KING regardless of the language or the type of book?? Heres the SQL i would use for all 3 "search parameters": PHP Code:

View Replies !
Writing Conditional Statement
I'm trying write a conditional statement that updates the database in 1 of 2 ways depending on the values given. I'm only 2 weeks into learning PHP/MySQL so I realize the way I've written it out is probably sloppy and more inefficient than what it could be. I've just been winging it from examples and trial and error and have gotten everything working except for this. I'm not sure if I have my logic or syntax wrong.

Application-specific details:
This is a simple invoicing application. Every invoice is in either 1 of 3 states:

- pending (default state when a new invoice is entered)
- paid (state when invoice is paid in full)
- partial (state when only partial payments have been made on the invoice)

What I'm trying to do is this:

1. If a partial payment is made on an invoice, the status is set to 'partial' (this is working)
2. If the payment posted was the full amount of the invoice or the final amount needed to pay it in full, the status is set to 'paid' (this is not working)

My processing logic works like this:
1. There is a total invoice amount stored in the invoice table represented by $total variable (working)
2. When payments have been made to that invoice (stored in the payments table), I show the remaining balance on their invoice by calculating the sum of those payments and subtracting them from the total (this is represented by the $diff variable and is working)
3. The part not working: When the remaining balance ($diff) minus the payment amount posted ($_POST['amount']) is equal to 0, the status is set to paid. PHP Code:

View Replies !
Mutlipart And/or Conditional Form
I have a form that needs to have conditional statements, and I am not sure how to "fix" this. The existing form is split in two parts - the form, and the processor. I would think that I will need to combine them, but..

Anyways - what I need is somewhat simple - if a certain option (from a <select>) is chosen, force another field to be completed. I also have 2 other fields that if the radio button is set to YES, require new fields. Ideally, the optional fields would only be shown to the user IF they are required.

View Replies !
Conditional Select From Mysql
I have a mysql database which stores race data that I want to open up to users for viewing. I want the user to be able to select various subsets of the data according to the parameters: race, gender, age, and type (and maybe sometime, by name as well). This is BOTH a mysql question and a php one, as I ask for a more efficient solution (see bottom this post).

Here is a snippet of how I am implementing the mysql statements to select only the exact subset of data. PHP Code:

View Replies !
Conditional Preg Match
The following bit of code does a preg match and does something if true
(sets $browser to ppcie)

Without using if then and else's how do I code it so it does not equal
what it is testing for? So if it does not find ppc in the $agent then
it does something else/sets it to something else?

$agent = getenv("HTTP_USER_AGENT");
if (preg_match("/PPC/i", "$agent")) {
$browser = 'PPCIE'
}

View Replies !
Debugging - Conditional Expression
I have a conditional expression that looks like this:

if (($mtf->nntp_id || $mtf->mlist_id) && !$mtf->mlist_msg_id) {


I want to get it to output the values of $mtf->nntp_id and $id variables.....

View Replies !
Help With Posting Conditional If Statement
I've tried scaling down a script to the bare minimum and
it still is not working correctly. What I think should happen is that when
the field app_fname is blank, that $hold_chk will get set to 1 and the 1st
if statement will be executed. What actually happens is that when I hit
submit, the form stays where it is, for example if the form where the submit
button is located is on the form other.php, then when I hit submit this is
where it stays. If I then hit the submit button a 2nd time, it post to the
some.php form. I've tried this script without the conditional if(isset()
and it works. I need to have the isset() otherwise the form displays all
empty fields as soon as it loads, before the submit button is hit.

<?php

$holdchk = 0;

if (isset($_POST['B1'])) {

echo "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk == 1 ){
echo "<form method="POST" action="some.php">";

}

if ($holdchk == 0 ){
echo "<form method="POST" action="other.php">";

}
}
?>

<html>

<head>
</head>

<form method="POST" action="">

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

View Replies !
Conditional List Boxes
I am attempting to create a list box that is dynamically populated based on the selection of another list box.  I am in way over my head..only way to learn I guess.  The code below has a year listbox and then based on the year selection, the page should either show another listbox (show industry selection when year <> 2005) or it should render the main form (when year=2005). I cannot get the main form to appear. Code:

View Replies !
Conditional Statement 'Begins With'
I am trying to pass a form variable that a user would enter a postcode/zipcode value and cannot get the conditional statement to work. What I want to happen is when a user enter a postcode/zipcode ie: CF2 I want to set the condition to the first two letters 'CF' so if it 'begins with' 'CF' then displays on price and 'does not begin with' 'CF' shows another price. see below what I have so far come up with PHP Code:

if($_SESSION['cboBolton'] == 'No')
  $int_sale_fee = 0.00;
else if($_SESSION['cboBolton'] == 'Yes' && $_SESSION['txtPostcode_A'] == "CF")
  $int_sale_fee = 350;
else if($_SESSION['cboBolton'] == 'Yes' && $_SESSION['txtPostcode_A'] != "CF")
  $int_sale_fee = 50;

View Replies !
Function Like A Conditional Statement
how to use the function which works like a conditional statement.

I think it is something like: 3 < 4 : $something ? $something

View Replies !
Conditional Execution In Apache
We have a school site which is heavily developed in php and works fantastic. Php tags are parsed in extensions php AND html. We want to add student areas (like www.ourschool.org/~bloggsf) where students can post up web pages.

However, for security reasons, we would like apache NOT to parse <?php code in their areas. In fact, we dont want them doing any form of CGI really, cos the little blighters will wreck *something*, guaranteed!

This is on Apache2, on a Fedora core 4 box, php5.1.2.

View Replies !
Conditional Form Submission
I have an html form that submits to a page on an external site. It basically submits an e-mail field. I want to create a conditional statement, where if the e-mail field is empty, the page does not submit.

If the field is populated, it refers the user to a page on my site. Is it possible to do this without modifying the code to which the page submits to? Can I catch the variable before the form "submits", and still submit the data?

View Replies !
Conditional Statement To Check
I'm modifying some old code on our system and have ran into this stupid roadblock. Essentially, the old system had these lre_codes with values 1-8. The lre_codes have been changed and now have the following values (32,35,13,34,15,16,36,33). Here is the way the original code was written. PHP Code:

if (($lre_code>0)&&($lre_code<9)){
    $cnts['s_d'][$lre_code][$lre_1077_age]=$cnts['s_d'][$lre_code][$lre_1077_age]+1;
    $cnts['s_d'][$lre_code]['total']=$cnts['s_d'][$lre_code]['total']+1;
    $cnts['s_d']['age_counts'][$lre_1077_age]=$cnts['s_d']['age_counts'][$lre_1077_age]+1;
    $cnts['s_d']['grandtotal']=$cnts['s_d']['grandtotal']+1;
}

I need to change the if statement to check for the above codes and I just can't figure out how to get it to work. Very simple, most likely.

View Replies !
Trim And Conditional Statement
$_REQUEST['statement'] = (trim($_REQUEST['statement']) != "" ? $_REQUEST['statement'] : $_LANG['Nostatement']);

Can someone tell me what the above is doing? Statement is always truncated in output, obviously because of trim, but what does the whole statement do?

Can i just take out trim? Is the trim the problem, i thought it only takes out whitespaces.

View Replies !
Conditional Echoes Functions
I it possible to use conditional echoes to determine which set of php appears on the page:

I have three sets of calendar scripts, and I need each to appear when a column value is being satisfied (how might these appear combined, if this can be done? there are about 25 different values so please keep sets together): Code:

View Replies !
Conditional Search An XML File
I have a form that has four fields, when i submit I writes all the fields value to an XML file, its not writing but APPENDING so the new record comes to the end of file Code:

View Replies !
OnClick- Conditional Statement
What I'm trying to do is make an if statement for when somebody clicks on an image. What I want to happen-(this is for an upload form):

1. The User fills in the info about the video
2. THEN they have to click on the image before the "upload" button appears.

I don't know if I should use JavaScript's "onClick", or create a function which allows the "upload" button to appear.

View Replies !
Conditional Relpace Line
$string = "abcde";
$file = file_get_contents($myfile);
if ($string_is_the_first_five_chars_of_a_line){
replace that line with $string.$string2;
}else{
add $string.$string2 to the end
}

View Replies !
How To Add Conditional Cell Formatting Using Css
My goal is retrive data from csv or mysql and place them in a table in a certain formatting. I couldn't figure out how can I insert css sytles in php using conditional conditions such as: Code:

View Replies !
Basic Conditional Check
PHP Code:

<?php
// Do we have authorization?
if (isset($password)) {
    if (sha1($password)==="e66799002ee9f20bc25becb7ef414be7bf391bf5" && sha1($username)==="e66799002ee9f20bc25becb7ef414be7bf391bf5") {
        $authorized=="yep";
        print 'Authorized! ('.$action.')<hr size="1" />'
//.... stuff trimmed
echo $action. " ". $authorized; //prints detail yep
if ($action=="detail" && $authorized=="yep") {
    $result = mysql_query("SELECT * FROM `table` WHERE `UID`='$uid' LIMIT 1");
//....
} elseif ($action=="insert" && $authorized=="yep") {
//....
} else { }?>

View Replies !
Htaccess Conditional Statement
I have this setting in my htaccess file: Code:

php_flag magic_quotes_gpc 0
php_flag magic_quotes_runtime 0

I have based my program around this, and I don't want to turn it on. I am trying to integrate phpshop, I require access to the session array so I simply Code:

<?php
require_once ($rootDir.'public_html/phpshop/index.php');
?>

View Replies !
Hide A Link Conditional
it possible to hide an ahref link with php conditional on what the url is: Example: I use an off the shelf CMS that will only allow searching pages if the parent category is published as "visible". I don't want the parent category link in the navigation though so I was wondering if PHP could hide the link, maybe conditional on what the link (URL) is.

View Replies !
Conditional Email Text To Hyperlink
I am trying to write a content management section for a web site.

I have managed so far to use htmlarea to give users a basic, but user
friendly interface by which to edit the page content.

The user can add emails by symply typing john@example.com - IE automatically
converts this to a hyperlink. The trouble is sometimes the users use plain
text. I have been using the following line to convert plain text to a
hyperlink:

$pagetext=ereg_replace('[A-Za-z0-9_]([-._]?[A-Za-z0-9])*@[A-Za-z0-9]([-.]?[A-Za-z0-9])*.[A-Za-z]+',
'<a href="mailto:?subject=Email%20from%20web%20site"></a> ',
$pagetext);

This works well - BUT it completely screws up any existing hyperlinks. Is
there a way to convert the plain text email address in to a hyperlink only
if it is NOT part of a hyperlink.

Basically I need some way of checking
* If it's plain text > convert to a hyperlink
* If it's already an email hyperlink leave it alone.

I have tried looking up and testing everything I can think of - but am
finally asking around before I go mad.

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved