PHP - Find Value Inside Foreach And Use If Statment On That One
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>"; }
Similar Tutorialsim 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; ?> Hi all, I am trying to write a script that finds the blank $_POST values and add them to a $blank_array. All I get is a blank page - any ideas? Also is there some code I can put at the top of every php page to show exactly what the errors are? - I have tried a few scripts but have not found one to work universally. include("cxn.php"); $reg = "G-".strtoupper($_POST['reg']); $sql = "SELECT * FROM sales WHERE reg='$reg'"; $result = mysqli_query($cxn,$sql) or die ("Couldn't execute query"); $num = mysqli_num_rows($result); if ($num >0) // Listing Already Found { echo "The aircraft '$reg' is already listed!"; echo $_SESSION['logname']; } foreach ($_POST as $value) { if ($value == "") { $blank_array[] = $field; } if (@sizeof($blank_array) > 0) // blank fields are found { $error = "Please fill in all the form.<br>"; include ("../sell-your-reg.php"); } } ?> 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"); } I get this error so I was wondering if it is because I can't put a while inside a foreach? "syntax error, unexpected T_WHILE in home/g/h/t...." while($rows=mysql_fetch_array($rr)){ $pt_id = unserialize($rows['pts']); foreach ($pt_id as $indiv) { $q = "select * from indiv where id_incr = '$indiv'"; echo $q; $result = mysql_query($q) while $ptrow =mysql_fetch_array($result)){ echo $ptrow['v1']; echo "<br>"; } } } Hi everyone, greetings from Brazil.
I am an average php coder, much more a designer than an programer, and i am in a looper trouble..
Can anyone try to help me?
Here is my code:
<table border="1"> <tr> <?php //pega cada uma das operadoras do campo operadoras $operadoras = $opers_trazOperadoras ; $logos = explode(",",$operadoras); $x = 0 ; foreach ($logos as $v) { mysql_select_db($database_webroker, $webroker); $query_trazLogoOperadora = "SELECT * FROM tb_operadora WHERE tb_operadora.id_operadora = " . $v ; $trazLogoOperadora = mysql_query($query_trazLogoOperadora, $webroker) or die(mysql_error()); $row_trazLogoOperadora = mysql_fetch_assoc($trazLogoOperadora); $totalRows_trazLogoOperadora = mysql_num_rows($trazLogoOperadora); ?> <td><img src="http://www.we-broker...imagens_upload/<?php echo $row_trazLogoOperadora['logo']; ?>"> <?php do { ?> <?php } while ($x++ < 4); { echo $x ;?> </td></tr><tr> <?php } $x = 0 ; } ?> </table> The URL for this code is: http://valsegs.we-br...radorasPATO.php Tks! I want to create a loop foreach [@attributes] I seem to be stuck and cant figure it out. any info would be helpful. Thanks! Code: [Select] Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [ID] => 5760861 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [ID] => 5335615 ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [ID] => 6080572 ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [ID] => 5178898 ) ) ) Hi.. I have table which has a data so_month: FromMonth : 5 ToMonth : 7 and I have table working_days: MonthName May Jun Jul MonthNumber 05 06 07 WorkingDays 23 24 23 Now I have function to get the 3 consecutive months from FromMonth to ToMonth , which as you can see from May to Jul Now I have problem in getting the SUM of Working days. here is my code: <?php $sql = "SELECT FromMonth, ToMonth FROM so_month"; $res = mysql_query($sql,$con); $row = mysql_fetch_assoc($res); $FromMonth = $row['FromMonth']; $ToMonth = $row['ToMonth']; function monthNames($from, $to){ $range=array(); for($i=$from; $i<=$to; $i++){ $range[$i]=date('M', mktime(0,0,0,$i)); } return $range; } $month_ = implode("' ', ",monthNames($FromMonth,$ToMonth)); foreach( monthNames($FromMonth, $ToMonth) as $month){ $sql = "SELECT MonthName, SUM(WorkingDays) AS WorkingDays FROM working_days WHERE MonthName IN ('$month') GROUP BY MonthName"; $res = mysql_query($sql, $con); while($row = mysql_fetch_array($res)){ $WorkingDays = $row['WorkingDays']; } echo $WorkingDays; } ?> the output of this code is: 232423 and when I change this line: $WorkingDays = $row['WorkingDays']; to $WorkingDays += $row['WorkingDays']; the output is: 234770 I correct output should be: 70 Any help is highly appreciated. Thank you very much.. I know this won't be possible with DOC, but it should be with DOCX. Basically I want to have someone write up a docx file using special tokens in certain places. Then my PHP would find and replace those tokens when the users needs to. It would create and serve a NEW docx file with the tokens replaced. Any ideas on this? I'm reading up on a ton of libraries, but nearly all of them, their examples don't work out of the box. Thanks! <?php function test(){ $x = ''; $arr = array('co'=>'color','ct'=>'design','cv'=>'weight','cm'=>'hight','cp'=>'price'); foreach($arr as $k=> $v){ $x .= '<tr><td> Td '.$k.' </td><td> Td '.$v.'</td></tr>' /* AFTER ACCESS THE ROW THAT DISPLAY "<tr><td> Td ct </td><td>Td design </td></tr>" */ /* insert HTML CODE (not by echo ) then complete the loop */ } return $x; } ?>
I have a table called "playlists", and a table called "musics". In the musics table, there is a column playlist_id which references the playlist that each music is contained.
I'm using api calls to display information on the site with JavaScript, so I need to return a JSON.
I need the json with the following structu
[
Playlists: [
{
Name: "etc",
musics: [
{
name: "teste.mp3" }, { name: "test2.mp3" } ] }, ... ] ] And this is my code: $query = $con->prepare("SELECT * FROM playlists WHERE user_id = :id"); I'm not sure if the title explains it very well, but here is an image of it. I am trying to figure out how to access the option selected (equal, not equal, etc.), along with its input box, for each column (the checkboxes on the right) selected. The purpose of this is to allow a non-programming administrator user to create a custom query to access information. I can find out which checkboxes are selected no problem, but finding the accompanying drop-down option and input box is difficult for me. How do I do this? If you have a suggestion on how to change it, I'm very open. Thank you in advance! Code: [Select] if(!isset($_POST['submit'])) { echo " <form method='post'> <table> <tr> <td valign='top'>SELECT</td> <td valign='top'> <table>"; // LIST ALL COLUMNS IN A TABLE $result = mysql_query("SELECT * FROM table_name") or die(mysql_error()); $rowcount=mysql_num_rows($result); $y=mysql_num_fields($result); for ($x=0; $x<$y; $x++) { echo " <tr> <td> <input type='checkbox' name='fields[]' value='".mysql_field_name($result, $x)."'>".mysql_field_name($result, $x)." </td> </tr>"; } echo " </table> </td> <td valign='top'>FROM allocations</td> <td valign='top'>WHERE</td> <td> <table>"; // LIST ALL COLUMNS IN A TABLE $result = mysql_query("SELECT * FROM table_name") or die(mysql_error()); $rowcount=mysql_num_rows($result); $y=mysql_num_fields($result); for ($x=0; $x<$y; $x++) { echo " <tr> <td> <input type='checkbox' name='column[]' value='".mysql_field_name($result, $x)."'>".mysql_field_name($result, $x)." </td> <td> <select name='operator[]'> <option value='='>equals</option> <option value='<>'>does not equal</option> <option value='>'>greater than</option> <option value='<'>less than</option> <option value='>='>greater than or equal to</option> <option value='<='>less than or equal to</option> <option value='LIKE'>is like</option> </select> </td> <td><input type='text' name='criteria[]'></td> </tr>"; } echo " </table> </td> <td valign='top'><input type='submit' value='Process Query' name='submit' class='submit'></td> </tr> </table> </form>"; } else { echo "<b>Fields to edit:</b> "; foreach ($_POST['fields'] as $fields) { echo $fields,", "; } echo "<br><br>"; echo "<b>Columns to query:</b> "; foreach ($_POST['column'] as $columns) { echo $columns," HERE IS THE SPOT, "; } } 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"; ?> 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.. 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 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... 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> } } ?> 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. <?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; } 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"; } ?> |