PHP - Need Help Putting An If Statment In My Loop
hello.
im having trouble putting an if statment in my loop this is my loop. Code: [Select] <div id="ddtabs3" class="solidblockmenu"> <ul> <?PHP foreach($topNav as $topNavs): ?> <li><a href="<?PHP echo $topNavs->title; ?>.php" id="<?PHP echo $topNavs->title; ?>"><?PHP echo $topNavs->title; ?></a></li> <?PHP endforeach; ?> </ul> </div><!-- #ddtabs3--> i what to add an if $pageName = '$topNavs->title'; then <li class = selected> any ideas thanks rick Similar TutorialsI have a while loop that works fine but when I add an if condition within the loop it does not echo the if condition. I'm trying to echo an extra row in the table if the number of clubs returned is > 2 <?php for($i = 0; ($ClubDetails1 = mysql_fetch_assoc($ClubDetails)) && $i < 2; $i++){ ?> <tr> <th scope="col"></th> <th scope="col"><?php echo $ClubDetails1['name']; ?></th> <?php if ($i > 2) { echo "<th scope=\"col\"><a href=\"club_page.php\"> More </a> </th>"; } ?> </tr> <?php } ?> im having problems with the count in the if statment. its only counting the last value _posted. im missing something really simple but i can not see it. help please. Code: [Select] <?php $count= $_GET['seatco']; for ($i=1; $i<=$count; $i++) { $ticket = $_POST['tick_com'.$i]; echo "tickets: ".$ticket; echo "<br>"; $adult= "0"; $child= "0"; $concession = "0"; if ($ticket =="adult") { $adult++; } elseif($ticket == "child"){ $child++; } elseif($ticket =="concession"){ $conc++; } else{ echo "no";} } } echo "Adult".$adult; echo "Child".$child; echo "Concession".$conc; ?> So here's what I got: $getwall2 = "SELECT comments.comment, wallposts.message FROM comments, wallposts where comments.byuser='$username' and wallposts.person='$username' ORDER BY dtime DESC LIMIT 0, 10"; $connectgetwall2 = $database->query($getwall2); $wall2 = mysql_fetch_array($connectgetwall2); echo "<table><tr><td>"; echo "<br><h2><img src=\"view.php?user=$user\" width=55 height=40> "; echo "<a href=\"userinfo.php?user=$user\"> $user</a> " .$wall2; echo "</h2></tr></td>"; echo "<tr><td>"; I still can't get it working, I can't figure out how to retrieve from two different tables, put it into one loop and have it seperate comments from wallposts into different tables ordering by when they were posted. If you need an example for what I'm looking for, think of how they have wallposts and status updates posted on your wall on facebook. Help would be highly appreciated! I'm trying to take a number of items from a database using a while loop and put the results into a variable so that I can send one email with all the results. I'm having trouble figuring this out though. Can anyone please give me any ideas as to how to make this work? Here's what I've done so far... all it does is result in an email with the first set of results in the while loop, not all of them. Code: [Select] <?php include("conf.inc.php"); $result = mysql_query("SELECT `to`,`from`,`subject`,`message`,`date` FROM allmsgs WHERE reported = 'n' ORDER BY `messid` ASC"); $row = mysql_fetch_row($result); $cdate = date('m-d-Y'); $sendto = "List@emails.here"; $emailsubject = "Webstats Report For $cdate."; while ($row = mysql_fetch_row($result)) { $to = $row[0]; $from = $row[1]; $subject = $row[2]; $message = $row[3]; $datetime = $row[4]; $eachmessage = "<p> <table width=\"400\"> <tr> <td> <hr width=\"400\"> To: $to<br> From: $from<br> On $datetime<br> <br> $subject<br> <br> $message </td> </tr> </table> </p>"; } $emailmessage = "<html> <body> <p>Here is a list of the messages that have been exchanged in the last 24 hours using the webstat system system.</p> $eachmessage </body> </html>"; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: Webstats <reports@webstats.com>' . "\r\n"; // Mail it mail($sendto, $emailsubject, $emailmessage, $headers); ?> So im trying to figure out if a user is already in the table so im checking for the number of rows where the user id shows up on a record and if its greater then one redirect them. My problem is the if statment does not work and I know there is more then one row. Also die ($row2); wont output data but it will in a sentence (see code below for example) Code: [Select] $sql2 = "SELECT * FROM purchases WHERE nid = '$id' AND uid = '$user_id'"; $res2 =mysql_query($sql2) or die (mysql_error()); $row2 = mysql_num_rows($res2); die($row2);//no output die("There are a total of ".$row2." rows");//outputs There are a total of 20 rows if ($row2 > 0){//if statment doesnt work. //already bought the note header("Location: view.php?error=2"); } hey guys i have a car dealer script and i want to make the interface look better.. so i want to put icons(door locks-ac-auto-manu-4 door..) my issue is the if.. so im guessing <? if ( $row3['Door_locks'] == 1 ) { echo "<img src="icons/Doors.png" width="32" height="32" border="0">";} ?> Hi guys, hopfully you can help me write out an if Statment; basically i want to make an "IF" statment to check if the user has purchased a "ticket" within the last 24 hours, if so echo YES if not echo NO the 'ticket' database is setup as follows: auctionID promoID username charID ticketNumber ticketPrice purchaseDate - Example:" 20101228 11:59:25" it will include the WHERE clause of "username =$username" can someone help me please, im not good with time based stuff.. Hey there fellow PHP coders I am sorta a newbie with php but i am having a heck of a time with this If Else statement and i know someone with experience will be able to tell me why the else if is not working What this is here is on our company intranet our agent love to send out flyers without picture and makes us look bad... so this is an IF Else if there is a picture display the eFlyer options else dont display the flyer options If doesnt seem to do the else can anyone see something that i am not seeing i have been staring at it for 2 hours now trying different little things and havent been able to get it to work PLEASE PLEASE help me thanks for everyone who reads this <?php if( $mlsInfo['PhotoURL'] != "") echo "<a href='emailListing.php?type=rs&mlsn=".$propInfo['MLSNumber']."' target='_blank' onMouseOver='doTooltip(event, 0)' onMouseOut='hideTip()' ><img src='images/buttons/fb_eListing.gif' width='106' height='20' border='0'></a> <a href='emailPostcard.php?type=rs&mlsn=".$propInfo['MLSNumber']."' target='_blank' onMouseOver='doTooltip(event, 2)' onMouseOut='hideTip()' ><img src='images/buttons/fb_ePostcards.gif' width='106' height='20' border='0'></a> <a href='emailFlyer.php?type=rs&mlsn=".$propInfo['MLSNumber']."' target='_blank' onMouseOver='doTooltip(event, 3)' onMouseOut='hideTip()' ><img src='images/buttons/fb_Flyer.gif' width='110' height='20' border='0'></a> <a href='../print_rs.php?type=rs&mlsn=".$propInfo['MLSNumber']."' target='_blank' onMouseOver='doTooltip(event, 5)' onMouseOut='hideTip()' ><img src='images/buttons/fb_printFlyer.gif' width='106' height='20' border='0'></a> <a href='fb_propertyRS_print.php?type=rs&mlsn=".$propInfo['MLSNumber']."' target='_blank' onMouseOver='doTooltip(event, 4)' onMouseOut='hideTip()' ><img src='images/buttons/fb_printListing.gif' width='106' height='20' border='0'></a> "; else echo "You Dont have any photos please add some"; ?> im having a few problems with if and endif see line of code below what have i done wrong <? if($forum_user['g_id'] <= USER_MOD):?><th class="tcr"><?php echo $lang_online['IP'] ?></th><?php echo "\n";endif ?> keeps kicking up error: Parse error: syntax error, unexpected T_ENDIF thanks Hiya peeps, I was wondering if anyone could help. I have a search page that returns and array, if there are no results. It will either not exist or it will be empty. I was wondering how I would check this and if its not empty how I would count how many other arrays are inside it, as it will be array(array(1=>'1', 2=>'2')); if it is not empty, for instance. if(empty($searchObj->compResult) OR !isset($searchObj->compResult)) { echo 'its empty'; } else { $count = count($searchObj->compResult); } Many thanks, James. this code works fine if the conditions are absolute ( pass, fail or empty). im trying to make the fail work if its part of the query. ive tried %fail% but didnt work. $choice = strtoupper($rows['comments']); if($choice == "PASS"){ $bgc = "#ff25f0" ; } elseif($choice == "FAIL"){ $bgc = "#666666" ; }else{ $bgc = "#FF6600" ; } <?php //include the connect script include "../../connect.php"; //Post variables from flash $username = $_POST['username']; $friend= $_POST['friend']; $status = $_POST['status']; $username = stripslashes($username); $status = stripslashes($status); $friend = stripslashes($friend); $username = mysql_real_escape_string($username); $status = mysql_real_escape_string($status); $friend = mysql_real_escape_string($friend); $sql = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username'"); $rows = mysql_num_rows($sql); $your_username=$rows['username']; if($rows > 0) { $sql1 = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username' and friend = '$friend' and status ='$status'"); $rows = mysql_num_rows($sql1); if($username && $friend && $status == "0" || $username && $friend && $status == "1") { echo "&msgTextfriendship= REQUESTED REJECTED ALREADY FRIENDS OR STATUS IS PENDING!"; return; } else { echo "&msgTextfriendship= REQUESTED NEW FRIEND SUCCESSFULLY!"; $insertnewfriend = mysql_query("INSERT INTO user_friends_list (username,friend,status) VALUES ('$friend','$username','0')") or die(mysql_error()); //$updateuserfriend = mysql_query("UPDATE user_friends_list SET status = '1' WHERE username = '$username' and friend = '$friend' and status ='0'"); return; } return; } else { echo "WiiStream Error!"; return; } ?> This right here I haven't tested it yet but I wanted to ask if this would work.. $sql1 = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username' and friend = '$friend' and status ='$status'"); $rows = mysql_num_rows($sql1); if($username && $friend && $status == "0" || $username && $friend && $status == "1") { echo "&msgTextfriendship= REQUESTED REJECTED ALREADY FRIENDS OR STATUS IS PENDING!"; return; } i can't seem to get the statment to work Code: [Select] $filename = $f; $name = $n; if ($n == $n){ include_once('test2.php'); mysql_query ("INSERT INTO images (filename) VALUES ('$n')"); }else{ include_once('test2.php'); mysql_query ("INSERT INTO images (filename) VALUES ('$f')"); }when i execute the code it seems only to upload to the database to when the $n values or false.. any ides what i can do.... before the question is asked there is no error code... This if statment is coming up true when its suppose to be false Only reason I can think of is there is a ton of rows with id matching $_session['user_id'] which doesnt make any sense to me Code: [Select] <?php $check3 = "SELECT id FROM pm WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'"; $check2 = mysql_query($check3) or die(mysql_error()); $check1 = mysql_num_rows($check2); if(empty($check1['id'])){ echo "Your Inbox is Empty"; } ?> I am inplanting a bonus system to a game i have. I want to say at first that i am not good at php am reading alot and go by learn by doing. But after a few hours i kinda gave up. Here is the code. The page end up blank. And i tested so my syntax work $cost and $points with only the db stuff and this code <div class="yellow_12_bold"><? print (number_format($points)); ?> </div> <div class="yellow_12_bold"><? print (number_format($cost)); ?> </div> And it does. Anyway here is the code Code: [Select] <? $dbq = $db->execute("select * from Bonus where username='$username'"); $points = $dbq->fields['points']; $allpoints = $dbq->fields['points_total']; $dbq->close(); if ($cost == "5" && $amount == "3000") { if ($points == "5" || $points > "5") { $sqlb = "update UserData set turns=turns+'3000' WHERE turns < 50000 and location != '9' and frozen = '0'"; $result1 = mysql_query($sqlb); $sqlc = "update Bonus set points=points-'5' WHERE username = '$username'; $result2 = mysql_query($sqlb); $points2 = ($points - 5); <p align="center" class="black">Thank you! 3000 turns have been added to everyone. You have <div class="yellow_12_bold"><? print (number_format($points)); ?> </div> bonus points left. </p> } else { <p align="center" class="black">Sorry you dont have $cost points. You have <div class="yellow_12_bold"><? print (number_format($points)); ?> </div> bonus points left.</p> } } ?> hi i am trying to count the number of clicks to an external link this is what i have come up with but it doesnt redirect but the if statment doesnt work properly because every time i click a link it always echos hello saying $add is not numeric when it is???? please help <html> <a href="index.php?add=1">Gamerforums</a><br> <a href="index.php?add=2">Google</a><br> <a href="index.php?add=3">Ebay</a><br> <a href="index.php?add=4">Paypal</a><br> <?php $add = $_GET['add']; include 'connect.inc'; if (is_numeric($add)) { mysql_query("UPDATE count SET clicks=clicks+1 WHERE id='$add'"); $result = mysql_query("SELECT * FROM count WHERE id='$add'"); $row = mysql_fetch_assoc($result); $url= $row[url]; header ("Location: $url"); } else { echo "hello"; } ?> </html> I can not get the below to work: if(time() < strtotime("11/21/2011 3:30AM EST") && time() > strtotime("11/21/2011 2:30PM EST")) It should be evaluating to true between 3:30 AM and 2:30 PM EST for today. Now that it's past 2:30PM it should be evaluating to false, but it's coming up as true. Edit: Nevermind. Cache/Cookies Issue. I have this simple piece of code. I am using GET[] to retrieve the catID from URL, then match it and set a backgorund image, some backgorund images can change per catID variable. When selected or clicked on. It is not working, it is producing the catId in ech $_Get[], but not matching it with $filename to set correct Image. Ex. Browser catID may == 1, it code displays catid = 1, file name = deals_2.jpg. This is worng. should be catid = 1 , filename = 1. PLEASE HELP, missing something. Code: [Select] <?php $imgpath = '/shushmedeals/templates/shushme_deals/images/'; //$bgimgID = $item->id; $bgimgID = isset($_GET['categoryId']); $bgimgID = $_GET['categoryId']; echo $bgimgID; //echo 'shoot her eman'; //echo $imgpath; if($bgimgID){ $bgimgID = 1; $filename = '/shushmedeals/templates/shushme_deals/images/bg_home.jpg'; } if($bgimgID = 2){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img1.jpg'; } if($bgimgID = 3){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img2.jpg'; } else { $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img3.jpg'; } if($filename){ echo '<br>'.$filename; // SET COOKIE //setcookie('bgimg', $filename); //echo $_COOKIE['bgimg']; } else { echo "There is no Background for this category"; // DO NOT SET COOKIE } // Print an individual cookie echo $_COOKIE["location"]; ?> Hi all..
My head just isn't working correctly today I can write this in english but can't think how to put this or even search for the code I'm looking for..
so I have a table such as this..
id - lineno - hitcount 1 - 2 - 0 2 - 2 - 0 3 - 3 - 0 4 - 3 - 1 5 - 4 - 0 6 - 4 - 0 7 - 4 - 0 And want to echo only if the hitcount is 0 for everything with a lineno of x So in this case I should return lines 1,2,5,6 & 7 but not 3. Any help appreciated Andy. I have a foreach loop in a webpage that displays some fields ($c), it looks like this: foreach($this->fDisplay[5] as $field) { $c = $this->field->showFieldValue($this->content,$field); if(($c !== "")&&($c !== null)) { $title = $this->field->showFieldTitle(@$this->content->catid,$field); echo "<span class='f".$field->name."'>"; if ($title != "") echo "<b>".htmlspecialchars($title)."</b>: "; echo "$c<br/>"; echo "</span>"; }
|