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.





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 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 !
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 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 !
An Endless Loop
This is a continuation of a previous thread:"Displaying text with
include file." This is the PHP include file.

I have about googled myself out on this one. If I have found what it is
I seek , I don't recognize it.

==========#
<?php
$data = file("outing.1.php");
foreach ($data as $line) {
$line = explode("_", $line);
print $line[&#390;'];
}

?>
============#
This code does exactly as expected. It prints to the screen the first
element of the array.

The array is of unknown length. I need to print to the screen all
elements. I have been able to do this with: for loops, while loops, do
loops, and some if statements, the problem is stopping when it reached
an empty element.

Even if I chose an arbitrary number to stop at, it would print the
elements and the balance in error lines.

View Replies !
Endless Menu
I'm using a menu using ul's(a little javascript but this isn't JS related) I have all my menu's items stored in a database. My table structure is. Code:

View Replies !
Function Goes Into Endless Loop
I'm trying to make a recursive function to search all subfolders for an index.php file and make one with this file's contents if there's not one there. But whenever I call the function, it sends the page into an infinite loop and I hit a maximum execution time error. This is the function:

<?php
function makeindex($start) {
foreach(glob($start . "/*") as $folder) {
if(filetype($folder) == "dir") {
if(!file_exists($folder . "/index.php")) {
file_put_contents($folder . "/index.php", file_get_contents("index.php"));
}
makeindex($folder);
}
}
}
?>
The main file's name itself is index.php, so with file_put_contents() I'm writing the contents of the index.php in the current directory.I'm calling the function with makeindex("").

View Replies !
Mysql Query With Near/endless Loop
I'm having a loop running in the folowing Query when I run it through Mysql command line (Only 1 row returns), but when I try it through a PHP page, it gets the "endless loop"...
Code:

View Replies !
Endless Loop? Empty Variables? What IS Going On?
1. it appears to be endless, as it freezes up my browser and never really ends

2. the variables are empty in the loop period .....

View Replies !
Endless Loop Script Crashing Apache
I'm using PHP 4.2.2 and Apache 2.0.4.0. A script running on a virtual
host had an endless loop in it that brought Apache to its knees. I have

max_execution_time=90
and memory_limit=32M

to handle larger file uploads and Gallery stuff (thumbnail processing)
but the script goes way past 90 seconds. Safe mode is off but the
script doesn't override it by using set_time_limit(). I have to restart
Apache to fix the problem. Apache Timeout is set to 300 seconds but
still goes way beyond that.

Any idea why the script might not be timing out?

View Replies !
Avoiding Load Time?
I have a script that takes quite a long time to load since the PHP is processing quite a lot of info. Is there any way I can initiate the script, then have it move on to another page right away so I don't have to wait for the PHP to finish processing? (having ignore_user_abort(); on so it will continue to process in the "background" - if my thinking is correct...)

View Replies !
Avoiding Duplicate Results??
Does anyone know if this is possible:

I'm running a query against a db and am pulling name and ticket # (for a helpdesk)...  What I'd like to do is take the results from the "Name" field, but only show EACH NAME ONCE in a table.  For example, I might get 200 results back, but only want to show the name of the person once, with how many tickets they have assigned to them.

So it would look like this:

___Name___|___Number of tickets___
___Bob____|__________3__________
___John____|_________23__________
___Mark____|_________4___________

...etc, etc...  does anyone know how to go about starting this?  I'm assuming an array of sorts. 

View Replies !
Avoiding Sent Mail To Spam?
Earlier this day i fixed my mail problem for account activation when someone registrates. I thougt that the mail() function didnt worked but instead it did worked by sending all the mails to my email spam. I've seen some code that avoids emails getting into spam.

View Replies !
Avoiding Guestbook Spam
One of my customers' site has been 'discovered' by the spammers community.

None of the messages they posted sofar ended up showing in the guestbook, since they fail to pass the correct verification string.(yes, available in written text and audio for the visually impaired)

Yet the volume and size of unsuccesful posts is increasing to a point where they may become a burden on server and bandwith. Code:

View Replies !
Avoiding Email Harvesters
To avoid email harvesters nabbing my clients emails would it be benneficial for me to create a script which when a user clicks an email link i.e. where id represents a number associated to an address in a database table -> emails.php?id=1

and is then redirected to a page with the appropriate header output to initiate the default mail client with the desired email address? If its worth it, how would i setup the headers to perform such an action (Ive already employed a contact form on the website but think its essential that end users/customers have access to actual/legit emails so as to send mail via their own mail clients/method).

I was considering the option of a script which utilises the GD extension to display the address' as an image on the page, however i would still require the above mentioned to be able to send the emails when a user clicks the link.

View Replies !
Avoiding Orphaned Records
If I want to delete a record but want to find out if that record_id is assigned to any other record in my db how do I appraoch this? So far my login is this: Code:

$sql = "SELECT COUNT (*) as numrows FROM " . $prefix . "_milpacs_members WHERE weapon_id = '$id'";
$row = $db->sql_query($sql);
$return = $row['numrows'];

I then display: Quote:

There are <?php echo $row['numrows'] ?> soldiers who have been assigned this weapon. Deleting this weapon will erase this from their record. Since my roster is displayed by matching unit_id = unit_id and weapon_id = weapon_id and such in various tables, I could have several members not displayed in my roster if I delete a weapon from my weapon table.

I think I need to enter a weapon_id of 0 into my weapon table and make the name "unassigned" then just update my members table for those who are assigned to the weapon I am attempting to delete and SET them to 0.

View Replies !
Avoiding Session Variables - How?
I've currently discovered the awesom power of session variables - and I'd like to leave such power to the Gods...

Question: I have to pass information from one php page to another, and not by a form. They will click a link to another page, and when they do I'd like a variable to be sent along.

I don't want to use a GET with the data in the URL, and I think using a post (if I could figure out how to outside of a form) is probably a bad idea. As as mentioned, I want to avoid session variables (I use them for login-state stuff and that's it).

View Replies !
Avoiding Double Submissions
I have a very simple mail script just to send a quick 'n dirty notification of a form posting -- it goes like this:

$message = $_POST["salutation"] . "", first_name = "".
$_POST["first_name"] . "",last_name = "". $_POST["last_name"] .
"",title = "" . $_POST["title"] . "", company = "" .
$_POST["company"] . "", leadsource = "" . $_POST["lead_source"] ;
$headers .= 'From: Sender <sender@blahblah.com>' . "
";
$subject = 'New record notification'
$to = 'recipient@blahblah.com'

// Mail it
mail($to, $subject, $message, $headers);


View Replies !
Writing A Review App But Avoiding Spamming
I want to write a revie module for some listings I have but I can imagine people posting 100s of times to say how great they are and 100s of times to slate their competitors.

I figure only allowing one review per listing from a particular IP address is a good start any other suggestions?

View Replies !
Avoiding Duplicate Array Elements
Im having a problem with this code. Im
trying to remove duplicate elements from an array created via $_GET.
I want users to be able to click on a link which sends an email
address to an array. I just want to remove duplicate email addresses
from the array. Ive tried array_unique() on my test server but it
doesnt work. So i tried to remove duplicates myself before storing
them into the array. The script works great without the checking,

session_start();

$email = $HTTP_GET_VARS['email'];
if (isset($_SESSION['Array']))
{

$Array = $_SESSION['Array'];
$numElements = count($Array);
for($counter=0; $counter < $numElements; $counter++)
{
/* Problem is here */if ($Array[$counter] == $email)
{
exit();
}

else
{
array_push($_SESSION['Array'],$email);
$EmailArray = $_SESSION['Array'];
$_SESSION['Array'] = $EmailArray;
}
}
}

else
{
$EmailArray = array();
array_push($EmailArray,$email);
$_SESSION['Array'] = $EmailArray;
}

View Replies !
Using Mail() And Avoiding Spam Boxes !
Im using the mail() command to send an email to people who register on
my site, but many are ending up in people's spam boxes on hotmail.

This problem isn't true of all users - probably around 60%.

Im being as open as possible using a number of headers, but can anyone
suggest a way of getting through with less problems ?

$sender = "From: Name <email@domain.com>" . "";
$sender .= "Return-Path: email@domain.com" . "";
$sender .= "MIME-Version: 1.0" . "";
$sender .= "Content-Type: text/plain; charset=iso-8859-1" . "";
$sender .= "Content-Transfer-Encoding: 8bit" . "";
$sender .= "X-Mailer: PHP/" . phpversion();

View Replies !
Avoiding Php Mail() To Spam Boxes
I'm sending soliticited emails for a nonprofit and i'm finding when i use PHP's mail function, and the mail goes through my ISP's SMTP, a decent percentage of the mails go to people's spam boxes.

are there known headers or something i could add to my code to make them less spam box prone?

View Replies !
Pass A Variable In A Url Avoiding Space In It
when I pass a variable in a url and the variable has a space in it, it causes problems, is there a way to not cause problems with that space.

Example url that causes issues

index.php?city=New York

Example url that does not

index.php?city=riverside

View Replies !
Avoiding Overwriting Temporary Files.
My PHP application produces and displays a report in HTML. It also produces a text file version of the same report which will be used as the "Printable Version" if the user wants that.

The text version will always have the same name, say STAFF.TXT My question is how do I avoid one user's STAFF.TXT of the file being overwritten by another user's STAFF.TXT ?

View Replies !
Avoiding Unpredefined Error Messages
This works:

if (!isset($_SESSION['logged_in']) || (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == "no")) {
show login form;
}

I need to be able to detect the dfference between 'was logged in during this session but has now logged out' and 'hasn't ever logged in'. Hence, the need to differentiate between an undefined $_SESSION['logged_in'], and $_SESSION['logged_in'] = "no".

View Replies !
PHP File Writing And Avoiding A Race Condition
So, PHP has this issue where you cannot lock a file until you open it, which leaves the door open for a race condition when writing files. I wrote the following code a while back and think it should work (and in fact use it and it works), I just thought I'd post it here for an audit and in case it might be useful for someone to use or I missed something!

/**
* Write a file to the server.
*
* First open a temp file for writing and acquire a lock.
* Proceed to write, unlock and copy the file from a temp file. If the
* file size is the same, the write worked, clean up and go home. if
* not, clean up and hope it works the next time.
*/
function cms_writeFile($filename, $tempfile, $data) {
$ft = fopen($tempfile, 'w');
if(flock($ft, LOCK_EX)) {
fwrite($ft, $data);
flock($ft, LOCK_UN);
fclose($ft);
if(copy($tempfile, $filename) && filesize($tempfile) == filesize($filename)) {
unlink($tempfile);
return true;
} else { // The whole process failed.
unlink($tempfile);
unlink($filename);
return false;
}
} else return false;
}

I pass it a random tempfile name, so at that point I think we avoid any race condition issues, but to be paranoid I check the file size after the copy. If the files are of a different size, I drop them both and hope this works the next time.

An example to use the function:

if(cms_writeFile('test.php', 'randomg-temp.php', 'some data')) {
echo 'written'
} else {
echo 'notwritten'
}

Seems right, and it works, am I missing anything?

View Replies !
Avoiding People To Create Twice An Account Using A Different Syntax.
I've a string that is used to write down a phone number that
comes from a form and would like to keep it as clean as possible. For
avoiding people to create twice an account using a different syntax.

For this the only char I'd like to allow are number 0-9, '/','.' and spaces.

I'd like to replace everything other by a "space".

Lets give some examples:

some allowed:
555/55.55.55
555 55 55 55
555.555 555

some not allowed and their changes:
555-55-55-55 -555.55.55.55
555,55,55,55 -555.55.55.55
555:55;55_55 -555.55.55.55
5555555>55 -55555.55.55
and so on.

View Replies !
Secure Mail Form (avoiding Spammers)
I want to create a simple web form in order to allow visitors to send me their comments via
email. I created this code:

$to = "mybox@mydomain.com";
$subject = "Comments from the web";
$body = "Comments:
";
$body = $body . "----------------------- ";
$body = $body . $email . "";
$body = $body . "----------------------- ";
$body = $body . $name . "";
$body = $body . "----------------------- ";
$body = $body . $text . "";
$headers = "From: $email";
mail($to,$subject,$body,$headers);


'$email' is the email address of the visitor, '$name' is their name, and '$text' is the contents of the comments.

But I found out that some spammers used this form to send spam. I didn't make any filter of the contents, and I was suggested they were using script injection within the form.

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 !

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