PHP - Help Writing Conditional Statement
I want to write a conditional statement like the following:
if ($value = "300x") { however, I want this to work if x is changed to anything. So the conditional should work if the following is true: if ($value = "300dog") { or if ($value = "300cat") { How do I make it work as long as 300 is present regardless of what follows after. Thanks in advance! Similar TutorialsI have a problem when trying to query the table closed_mbl. I want to return the COUNT of all records that contain the locations below while excluding all these records that contain anything else besides AIR. How would I do this? Right now it returns the count of everything from all these locations. The field "method" is ignored. SELECT COUNT(*) FROM closed_mbl WHERE location = 'ALL' OR location = 'AUCKLAND' OR location = 'BRAZIL' OR location = 'DALIAN' OR location = 'EXPORT' OR location = 'GALWAY' OR location = 'ISUNICOV' OR location = 'KOLIN' OR location = 'SGALWAY' OR location = 'SHANNON' OR location = 'SOMI' OR location = 'SUZHOU' OR location = 'UNICOV' OR location = 'WUJIANG' OR location = 'WUJIANGCC' AND method = 'AIR' Hi, I asked a question about Tokens earlier. After debugging I've found the reason as to why my program isn't working. It's related to this statement: if($token == $_SESSION['token']) { ........; return true; }$token is generated in form using md5(uniqid()). When I echo both $token and $_SESSION['token'] before the if statement they both turn out to be the same. Yet for some reason the if statement is not being satisfied and is not returning true as it's supposed to do. (I've tried $token === $_SESSION['token'] as well.) I don't know if some kind of type casting or other is required for the conditional statement to work. Would be grateful for any suggestions. Edited by mac_gyver, 30 October 2014 - 10:53 PM. removed links from copied text I have a membership directory that I've been working with for a long time, and recent server upgrades with MySQL, PHP, etc. forced me to do some recoding. While I was doing that, I wanted to try and make some improvements. I must give a brief description of the intent, and then the results I got, so someone can sort out the problem for me. I have a query that selects all "Agent" members, then orders them by County, then by Company Name. What I am trying to do is create a new heading in my list every time the County information changes as the list is sorted and output to my table.
I am going to attache 2 .php files with my code. The agent_member_list.php is the original code that pulls all of the members properly, and results can be viewed he http://www.nmlta.org...member_list.php
The agent2_member_list.php is where I'm trying to insert the new conditional statement to print my County headings when a new County is encountered in the results. The heading actually works, and changes correctly, but the problem is that the first member entry in every county is not printed in the output. I know the query is correct, so I'm sure I've got the conditional "if" for checking County field wrong, or misplaced. Here is the link to it: http://www.nmlta.org...member_list.php
I'm hoping someone can spot my error pretty quickly, I only dabble in this very rarely. Thanks for any help!
Attached Files
agent2_member_list.php 5.06KB
3 downloads
agent_member_list.php 4.82KB
2 downloads Hello, I am trying to have users select multiple options from a dropdown list. But before each selection, I would like to have a message appear on the screen asking if the user if they would like to select another option - Yes or No. Yes or No would be required fields. If the user select Yes, they can select another option from the drop down list (displaying all selected options on the screen before processing). If the user select No, they can proceed to the next fields. I have to searched the Internet for days, but was unable to locate anything close. If possible I would like to implement the amselect.js code into this difficult task. Can you guys please assist or point me in the right direction? I have the following code which seems to be in error in the conditional statement. The queries to the database produce the expected results, and the echo statements work OK. I want to make a selection based on whether data exists in the database for passState when passState=1. Can anyone tell me what is wrong with the conditional statement? Code: [Select] <?php $query1 = mysql_query("SELECT DISTINCT quizTitle, userId, passState, userScore, totalScore, DATE_FORMAT(userDate,'%b %e, %Y') AS userDate FROM quiz WHERE managerId = '$managerId' AND userId = '$userId' AND passState = 1 ORDER BY quizTitle ASC, passState DESC, userDate DESC "); $query2 = mysql_query("SELECT DISTINCT quizTitle, userId, passState, userScore, totalScore, DATE_FORMAT(userDate,'%b %e, %Y') AS userDate FROM quiz WHERE managerId = '$managerId' AND userId = '$userId' AND passState = 0 ORDER BY quizTitle ASC, passState DESC, userDate DESC "); ?> <table width="778" style="font-size:16px"> <tr> <?php if ($query1) { while ($row1 = mysql_fetch_array($query1)) { echo'<td width="13"></td> <td width="137" style="vertical-align:middle; text-align:left;">' ?> <?php echo "{$row1['quizTitle']} <br />\n"; ?> <?php echo '</td> <td width="13"></td> <td width="132" style="vertical-align:middle; text-align:left;;">' ?> <?php echo "{$row1['userDate']} <br />\n"; ?> <?php echo '</td> <td width="22"></td> <td width="112" style="text-align:center; text-align:center;">' ?> <?php if ("{$row1['passState']}" == 1) {echo "<img src=' ../wood/wood_tool_images/tick2.png' /><br />\n";}?> <?php echo '</td> <td width="30"></td> <td width="103" style="text-align:center; text-align:center;">' ?> <?php if ("{$row1['passState']}" == 0) {echo "<img src=' ../wood/wood_tool_images/cross2.png' /><br />\n";} ?> <?php echo '</td> <td width="19"></td> <td width="126" style="vertical-align:middle; text-align:center;">' ?> <?php echo "{$row1['userScore']}".'/'."{$row1['totalScore']} <br />\n"; ?> <?php echo '</td> <td width="23"></td> </tr>'; } }else{ while ($row2 = mysql_fetch_array($query2)) { echo '<td width="13"></td> <td width="137" style="vertical-align:middle; text-align:left;">' ?> <?php echo "{$row2['quizTitle']} <br />\n"; ?> <?php echo '</td> <td width="13"></td> <td width="132" style="vertical-align:middle; text-align:left;;">' ?> <?php echo "{$row2['userDate']} <br />\n"; ?> <?php echo '</td> <td width="22"></td> <td width="112" style="text-align:center; text-align:center;">' ?> <?php if ("{$row2['passState']}" == 1) {echo "<img src=' ../wood/wood_tool_images/tick2.png' /><br />\n";}?> <?php echo '</td> <td width="30"></td> <td width="103" style="text-align:center; text-align:center;">' ?> <?php if ("{$row2['passState']}" == 0) {echo "<img src=' ../wood/wood_tool_images/cross2.png' /><br />\n";} ?> <?php echo '</td> <td width="19"></td> <td width="126" style="vertical-align:middle; text-align:center;">' ?> <?php echo "{$row2['userScore']}".'/'."{$row2['totalScore']} <br />\n"; ?> <?php echo '</td> <td width="23"></td> </tr>'; } } ?> </table> Hi, Why doesn't this work? Driving me nuts! Thanks. <?php if($_SERVER[PHP_SELF] == 'somepage.php') { Header("Location: http://www.thissite.com"); } else { Header("Location: http://www.anothersite.com"); } ?> The code NEVER redirects to the first URL (thissite.com). It ALWAYS redirects to the second URL (anothersite.com). What the heck am I doing wrong? hey guys trying to find out what the short name of FireFox2 is. (for example the "IE 6" in this code) What would it be for firefox versions 2? Code: [Select] <!--[if IE 6]> <meta http-equiv="refresh" content="0; url=http://example.com/"> <![endif]--> THANKS!!! This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=318784.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=342336.0 Hi and thanks for taking the time to read through this first and foremost. I have a bit of code that I have managed to piece together with help from other sites and what it does is connect to our local ms sql server and retrieve a few tables from our database. The info is relating to property management and it basically displays the unit address, current date and its rental status. (Occupied or Vacant) This makes it easy for us to at a glance check the status of our rentals instead of having to log into our software and navigate through all that.. anyways, I have two issues I need help with. First problem, in my code, is it possible to write a conditional statement that would check for a certain status in a view and then if it is there, print a simple yes or no in a table with that appropriate property. For example, we have property 1000 name street and it is currently vacant, however the viewPendingLease shows us information regarding future bookings. I would like to be able to look through that view with the code, check property 1000 name street for any future pending leases, and if there is one, print out a "Yes" in a Future Booked column that I would create. If any of that makes sense, I can post the print out of the tables of the viewPendingLease if it makes it easier for anyone to see the data output to understand what I am meaning. The second issue, is it possible to change the color of the text according to a variable, say a word in a generated table with html or css? I would like to color the words vacant or occupied green and red respectively just to make it much easier to zero in on the vacant properties. Or even maybe just color every other row a background color just to help distinguish between the different properties. Here is my code that pulls up my current tables to show Property, Street and current rented status. Code: [Select] <?php //connect to a DSN "*******" $conn = odbc_connect('*******','*****','************'); if ($conn) { //the SQL statement that will query the database $query = "Select unit.PropertyUnitID, unit.Street, unit.Status, from unit"; //perform the query $result=odbc_exec($conn, $query); echo "<table border=\"1\"><tr>"; //print field name $colName = odbc_num_fields($result); for ($j=1; $j<= $colName; $j++) { echo "<th>"; echo odbc_field_name ($result, $j ); echo "</th>"; } //fetch tha data from the database while(odbc_fetch_row($result)) { echo "<tr>"; for($i=1;$i<=odbc_num_fields($result);$i++) { echo "<td>"; echo odbc_result($result,$i); echo "</td>"; } echo "</tr>"; } echo "</td> </tr>"; echo "</table >"; //close the connection odbc_close ($conn); } else echo "odbc not connected"; ?> I currently have the viewPendingLease.Active (which shows if there is a future pending lease) taken out due to a repeating data issue I am also trying to figure out... I'm having issues with the following: Code: [Select] <?php session_start(); $_SESSION['username']=$_POST['username']; $_SESSION['password']=$_POST['password']; if($_SESSION['username']=="username" && $_SESSION['password']=="password"){ if($_GET['product']=="add"){ $content.=' <p><label>Product Name:</label> <input type="text" name="product_name" size="30" /> <label>Product Price:</label> <input type="text" name="product_price" size="5" /> </p> <p><label>Product Category:</label> <input type="text" name="product_category" size="30" /></p> <p><label>Product Link:</label> <input type="text" name="product_link" size="30" /></p> <p><label>Product Image:</label> <input type="text" name="product_image" size="30" /></p> <p><label>Product Tag:</label> <input type="text" name="product_tag" size="30" /></p> <p><label>Product Keywords:</label> <input type="text" name="keyword" size="30" /></p> <p><label>Product Features:</label><br /> <textarea name="product_features" rows="10" cols="60"></textarea> </p> <p><label>Product Pros:</label><br /> <textarea name="product_pros" rows="5" cols="30"></textarea> </p> <p><label>Product Cons:</label><br /> <textarea name="product_cons" rows="5" cols="30"></textarea> </p> <p><label>Product Description:</label><br /> <textarea name="product_description" rows="10" cols="60"></textarea> </p> <p><label>Product Notes:</label><br /> <textarea name="product_notes" rows="5" cols="30"></textarea> </p> '; $logout='<div><a href="./acp_admincp.php?log-out">Log-Out</a></div>'; } elseif($_GET['product']=="view"){ } else{ $content.=' <a href="./admincp.php?product=add">Add New Product</a> <br /> <a href="./admincp.php?product=view">View Products</a> '; } } elseif(isset($_GET['log-out'])){ session_start(); session_unset(); session_destroy(); header("Location: ./admincp.php"); } else{ $content=' <form action="./admincp.php" method="post"> <p><label>Username:</label> <input type="text" name="username" size="30" />'; $content.='</p> <p><label>Password:</label> <input type="password" name="password" /></p>'; $content.='<p><input type="submit" value="Submit" name="Submit" /></p> </form>'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <base href="http://ghosthuntersportal.com/" /> <title>Ghost Hunter's Portal - Admin Control Panel</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="verify-v1" content="" /> <meta name="keywords" content="ghost, hunters, hunter, ghosts, spirit, spirits, paranormal, investigation, investigator, investigators, k2, emf, meter, kii" /> <meta name="description" content="Ghost Hunters Potal. Parnormal research equipment store." /> <meta name="author" content="Andrew McCarrick" /> <meta name="robots" content="index, follow" <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <img src="./logo.png" alt="Ghost Hunter's Portal Admin Control Panel" /> <br /> <div style="color: #AA44AA; font-size: 26px; margin-top: -30px; margin-left: 125px;">Admin Control Panel</div> <?php echo $logout; echo $content; ?> </body> </html> I can log-in, and get to the page with the two links on it. However, once I click one of the links it falls back to the log-in page, and it ends up being a never ending loop. It's doing this: Log-In --> Page with links ---> Log-In page again Should be doing this: Log-In --> Page with links --> Add Product page or View Products page I can never get into the the actual sub page. Just to be clear, the address bar actually shows product=add or product=view, but it still shows the log-in page. i wanna put condition that if ($signupbonus > 0.00) then following should not be executed <font size="3" color="red"><b>Referral bonus: <font color="green" size="4">$<? echo $signupbonus; ?></font></b></font><br><br> please help Hi,
I have a website that is 80% done when my programmer dropped the ball. I am trying to get it all to work, but have only rudimentary knowledge on what I am doing thus far and need a bit of help, please.
I have a couple of popups links that writes a reminder to check the size of necks and arms at the top of certain pages.
One of my product groups is called Collars and Armbands
which consists of 1 x category "Collars and Armbands" whic has 2 x Subcategories which are "Collars" and "Armbands" if I click on the "Collars and Armbands" tab, it displays all the contents of both subcategories Collars and Armbands, as expected. It displays the popup links for both subcategories. I don't want the popups to appear on the "Collars and Armbands" page but only on the individual "Collars" or "Armbands" pages if I click on Collars or Armbands subcategory tabs it displays the single popup link for that category. (which is what I want it to do) The problem lies in the category and subcategory names which I can't really change without making it non-logical for the customer. this the code that makes is happen if ( substr_count($sectionname,'Collars')>0 || substr_count($productname,'Collar')>0 ) { echo '<p class="measurelink noprint">Remember to <a href="neckmeasurepop.php" class="lnkpopup sllink" title="click for popup measuring instructions" onclick="slf_popupwin();return false;">Measure Your Collar Size !</a></p>'; } My question is, is there a way to set a condition that I can use for this code that says "if the $sectionname = "Collars" but NOT "Collars and Armbands" and $productname = "Collar" then display the popup link "neckmeasurepop.php". I had considered renaming the base category to something else, but that would just make things confusing for the customers. Cheers and thanks in advance Hello.
I have a sports league and the captain's page has a menu bar allowing links to sub pages. I would like to only add the URL part if a condition is met. In my database I have a league field called "session" for Spring or Summer sessions.
The menu bar has 5 simple columns for hyperlinks:
Home | Edit Team | Add Player | Edit My Information | Log Out |
What I would like to do is to only display say the "Edit Team" with hyperlink if the league session = "Summer" (that was Spring teams cannot edit their information at this point in time). I am trying to create an IF-Else statement, but can't quite get it right. I am a novice PHP coder, so I could really use some help. Here is the current code for this short section:
<table width="800" border="0" cellpadding="0" cellspacing="0"> <tr> <td><img src="images/BBV_CP_top.jpg" width="800" height="200"></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="6%" class="menu"><a href="home.php"> Home</a> </td> <td width="9%" class="menu">Edit Team </a></td> <td width="12%" class="menu">Add Player</td> <td width="63%" class="menu">Edit My Information</a> </td> <td width="10%" class="menu"><a href="logout.php">Log Out </a></td> </tr> </table>How can I create "Edit Team" to be a hyperlink ONLY IF the condition (league = Summer) is TRUE? $team is the query that returns the league results from the MSSQL query. Thanks in advance for your help. Hi, I've written a conditional statement to give my body tag a unique ID, depending on three conditions. (body id="red" etc..) The statement does indeed work when tested, but dreamweaver is highlighting the conditional in yellow - So I'm wondering if there is an alternate (and perhaps cleaner) way of writing the following.. It's for a joomla site btw.. (I've spread the code out a little here, so it's easier for you guys to see what I'm doing) Code: [Select] <body <?php if($this->countModules('headerlow')) : ?> id="up" <?php endif; ?> <?php if (JRequest::getVar('Itemid')==104) { ?> id="red" <? } else {?> id="low" <? } ?> > Hey, been banging my head against the wall for a couple of hours now. There is an If () in the code that is driving me crazy because it is not behaving like I expect it to.. foreach ( $types as $type ) { if ( !isset( $type->modclass ) or !isset( $type->typestr ) ) { debugging( 'Incorrect activity type in ' . $modname ); continue; } $var = (string)$type->type; if ( $var != 'assignment&type=online' ) { print '<br/>' . $var . '<br/>'; if ( $type->modclass == MOD_CLASS_RESOURCE ) { $resources[$type->type] = $type->typestr; } else { $activities[$type->type] = $type->typestr; } } } results in... Code: [Select] label resource&type=text resource&type=html resource&type=file resource&type=directory resource&type=ims assignment_group_start assignment&type=upload assignment&type=online assignment&type=uploadsingle assignment&type=offline assignment_group_end Notice the assignment&type=online in the output... I'm just about ready to give up as to why it is still outputting $var when it is clearly equal to the compared string? Any ideas? Hello, this is my first PHP project, and I am having issues getting it to correctly display an error ONLY if the input is an error It displays the error upon first load of the page w/o pressing submit. How would I use Code: [Select] isset($_POST['submit'])to fix it? Code: [Select] <?php $inputid = $_POST['steamid']; $steam_prefix = substr($inputid, 0, 10); $prefix_length = 10; $char_total = strlen($inputid); $steam_suffixchars = ($char_total - $prefix_length); $suffix_check = substr($inputid, 10, $steam_suffixchars); $class_set = "notranslate"; $is_submit = isset($_POST['submit']); if(is_numeric($suffix_check) == true) $suffix_valid = true; elseif(is_int($suffix_check) == false) $suffix_valid = false; if($char_total > 25 || $char_total < 11) $char_valid = false; else $char_valid = true; if($steam_prefix === "STEAM_0:1:" || $steam_prefix === "STEAM_0:0:") $prefix_check = true; elseif($steam_prefix != "STEAM_0:1:" || $steam_prefix != "STEAM_0:0:") $prefix_check = false; if (preg_match('/^[A-Z0-9-:-_-]+$/', $inputid)) $chars_matched = true; else $chars_matched = false; if($suffix_check == true && $prefix_check == true && $char_valid == true && $chars_matched == true) echo "Approved!"; elseif(isset($_POST['anon'])) echo "Approved!"; else echo "error!"; ?> I would like to have a script that would check certain parameters and if none of them returns TRUE, execute a set of codes. So the idea is somehow like if...else(). Code: [Select] <?php // trying to put if() directly within if() if ( // checking of variables if (!isset($transaction)) { echo '<font color="#FF0000">Type of transaction is not set.</font>'. '<br />'; } else { if ($transaction == 'sell') { if (empty($BV)) { echo '<font color="#FF0000">Book value is not set.</font>'. '<br />'; } } } if (empty($stock)) { echo '<font color="#FF0000">Stock symbol is not set.</font>'. '<br />'; } if (empty($price)) { echo '<font color="#FF0000">Price per share is not set.</font>'. '<br />'; } if (empty($volume)) { echo '<font color="#FF0000">Volume of shares is not set.</font>'. '<br />'; } ) { echo 'Go back and fill out necessary fields.'; } // if none of the above parameters returns TRUE else { echo 'Copy and paste the following in the email that you would be submitting.' </tr> <tr> <td> switch ($transaction) { case 'buy': include('calc_buy.php'); break; case 'sell': include('calc_sell.php'); break; default: echo '<font color="#FF0000"><b>If you see this message there is something wrong with your session. Please send us a feedback with the details of your session before seeing this message.</b></font>'; } } ?> This code returns an error and as I understand the error, it is because of if (if ()). How can I make it work? Thanks in advance! I am trying to identify the username from a series of windows logs. I have been using (?:User Name:|Account Name:)\s*([\S]+) and it works for examples 1-4, however I'm having problems with example 5. Because it has two occurrences of the pattern Account Name: in the string I can only get the regex to return the first match, i.e. USER-PC$. How can I tell regex, that if there are two Account Name: patterns in the string, or the string contains the pattern "New Logon:" then return the second Account Name: match, i.e. John.Doe? eg 1 - The screen saver was invoked. Subject: Security ID: S-X-X Account Name: John.Doe Account Domain: INTERNAL Logon ID: 0xa4091 Session ID: 1 eg 2 - User initiated logoff: Subject: Security ID: S-X-X Account Name: John.Doe Account Domain: INTERNAL Logon ID: 0x3d95c This event is generated when a logoff is initiated. No further user-initiated activity can occur. This event can be interpreted as a logoff event. eg 3 - User Logoff: User Name: John.Doe Domain: INTERNAL Logon ID: (0x0,0x458E4AB4) Logon Type: 8 eg 4 - Successful Network Logon: User Name: John.Doe Domain: INTERNAL Logon ID: (0x0,0x43) Logon Type: 8 Logon Process: Advapi Authentication Package: Negotiate Workstation Name: USER-PC Logon GUID: {2e483a4f-} Caller User Name: USER-PC $ Caller Domain: INTERNAL Caller Logon ID: (0x0,0x7) Caller Process ID: 4816 Transited Services: - Source Network Address: xx.xxx.xx.x Source Port: 35029 eg 5 - An account was successfully logged on. Subject: Security ID: S-X-X Account Name: USER-PC$ Account Domain: INTERNAL Logon ID: 0x3e7 Logon Type: 2 New Logon: Security ID: S-X-X Account Name: John.Doe Account Domain: INTERNAL Logon ID: 0xa4062 Logon GUID: {23-xx-22} Process Information: Process ID: 0x2fc Process Name: C:\Windows\System32\winlogon.exe Network Information: Workstation Name: USER-PC Source Network Address: xx.x.x.x Source Port: 0 Any help would be appreciated:) is it possible to have a script that changes header based on what page the user came from. something like Code: [Select] if ($_SERVER['HTTP_REFERER']) == http://www.site.com/pagebefore.php) { // do nothing, letting page generate } else { header("Location: back_to_the_start_buddy.php"); } |