PHP - Php Array Groups - Headers And Footers
Hi
I have a two dimensional array and would like to output the results in groups depending upon one of the fields in the array. While i have managed this and have figured out how to create a header for each group, i would now like to create a footer (end of group) line where i could create a subtotal or similar.
my working code with the header is below but how do i add the footer?
$group = null; for($i=0;$i<count($rowKitCharges);$i++){ if($rowKitCharges[$i]['SubCategory'] != $group) { //echo the group header echo "<br><b>" . $rowKitCharges[$i]['SubCategory'] . "</b><br>"; $group = $rowKitCharges[$i]['SubCategory']; } echo $rowKitCharges[$i]['HireID'] . " " . $rowKitCharges[$i]['SubCategory']; echo "<br>"; }Thanks Jon Similar TutorialsWhen using Firefox and other browsers they put in the header and footers the information in the page when you print, is there a way through PHP to actually not allow those to be printed or is this a manual option that is going to have to be selected every time I want to print? I know I am probably complicating this but I am looking for a way to code a header and footer to the exterme top and extreme bottom of my pages. I have seen it before but I have no idea how to do it from scratch. But I ore or less want to be able to edit my header or footer one time and it work every where. Thanks in advance. Hello Guys This is the first time i ask a question at php freaks. Hope i could find the answer. I want to create something similar to the image now the problem is that i want to get groups and their users in the same array. Notice something like Array => Group1 [1] => user1 [2] => user2 [3] => Group2 and so on. How could i do that. Thanks in advance. Hi, I need some help getting my head around arrays. I have a basket of fruit: $basket=("Apple","$Orange","$Banana","$Banana","$Peach","$Apple","$Banana","$Orange","$Apple"); I want to distribute and share this basket of fruit into bowls, such that each bowl contains the following: $bowl=("$Apple",$Orange,"$Banana","$Banana") ie. One Apple, One Orange & Two Bananas. I can't seem to figure out how to do it. Thanks in advance. Hello I am after some guidance on the following scenario: I have a news page that pulls from a database and would like to seperate it out by year, see below 2010 Bulletin 2 - 23/11/2010 - Some news here..... Bulletin 1 - 21/11/2010 - Some news here..... 2009 Bulletin 2 - 23/11/2009 - Some news here..... Bulletin 1 - 21/11/2009 - Some news here..... How can i do this automatically and seperate them out by year like above I'm using Active Directory and PHP with LDAP. I have been trying to create a script that will list all the members of each group in a OU. When I run this script in an OU with Users, it will return an array with all the available attributes of each User. However when I use it with a group, it doesn't return any attributes of the group. Code: [Select] <?php $ig_ldaphost="LDAP://domain/"; //filtered for security $ig_ldapou="OU=Drive Security,OU=Groups,DC=this,DC=and,dc=that"; //filtered for security $ig_ldapconn=ldap_connect($ig_ldaphost) or die("Could not connect to {$ig_ldaphost}"); $ig_ldapopt=ldap_set_option($ig_ldapconn,LDAP_OPT_PROTOCOL_VERSION,3) or die("Could not set options: {$ig_ldapopt}"); $ig_ldapbind=ldap_bind($ig_ldapconn) or die("Could not bind: {$ig_ldapbind}"); $ig_ldapsearch=ldap_search($ig_ldapconn,$ig_ldapou,"objectClass=*"); for ($ig_ldapentry=ldap_first_entry($ig_ldapconn,$ig_ldapsearch);$ig_ldapentry!=FALSE;$ig_ldapentry=ldap_next_entry($ig_ldapconn,$ig_ldapentry)) { $ig_ldapvalues=ldap_get_attributes($ig_ldapconn,$ig_ldapentry); $ig_ldapdn=ldap_explode_dn(ldap_get_dn($ig_ldapconn,$ig_ldapentry),1); echo "/".$ig_ldapdn[1]."/".$ig_ldapdn[0]."<br />"; var_dump($ig_ldapvalues); echo "<br /><br />"; } ldap_close($ig_ldapconn); ?> Can anyone help with this? I have a group of 4 radio buttons. my mysql database knows which one the user selected previously when they stored some information. I now wish to display the same buttons but have radio button checked that the user chose before. I know this can be done but having one of those mind melt moments where I cannot think of the solution so I have 4 buttons that look like this Code: [Select] <input type="radio" name="clarity" id="clarity" value="Opaque"> Opaque<br> <input type="radio" name="clarity" id="clarity" value="Deep"> Deep<br> <input type="radio" name="clarity" id="clarity" value="Mid"> Mid<br> <input type="radio" name="clarity" id="clarity" value="Pale"> Pale<br></td> I just need to attached a checked field to the correct item Dear all, I am new in this forum. This is my code $query = " SELECT webdb.id, webdb.writer, writer.picLoc, webdb.title FROM webdb, writer WHERE webdb.writer=writer.name and category = 'Researchworks' and language = 'Farsi' ORDER BY writer DESC"; $resultaat = mysql_query($query, $LinkID); $column_count = mysql_num_fields($resultaat) or die (mysql_error()."<br>Couldn't execute query: $SQLquery"); $counter=1; echo "<table border=\"0\" width=\"700\" border color=white><tr>"; while ($row = mysql_fetch_row($resultaat)) { if ($author !== $row[1]) { $author = $row[1]; echo "<td align=right width=220 valign=top style=\"margin: 5px; float: right border-bottom-color:#000; border-left-color:#000;\">"; echo "<img width=\"50\" height=\"80\" src=\"admin/writers/$row[2]\" border =\"0\"><br>".$row[1]."<br>"; echo "<a href=\"poems.php?writer=$row[1]\">".$row[3]."</a><br>"; echo "</td>"; if($counter%3==0) { echo"</tr><tr>"; } $counter++; } } echo"</tr></table>"; i have authors with different articles on a certain topic. What i want is, displaying the name of the author only once and all his titles under his name. I also want a dynamic table where i display three authors in each row and soon as there a fourth author a new row must start. My problem now is is the title is also being filtered and i can only display one title. Thanks in advance Hi, I know very little about binding PHP to AD. At the minute it is setup to Authenticate against AD (Via IIS), then from the that I have the following: Declare's the Logon_Name variable, so that it can be used to 'print' buttons, and links i.e. if ($logon_name==("Administrator")); {echo admin link here'}; $logon_name = basename($_SERVER['AUTH_USER']); What I would ideally like to do is be able to find the group the user is a member of, this way we can create custom AD groups like intra_admin and then if they are a member they will be able to see certain links to pages etc. Any ideas, I hope this makes sence Hello,
I am sending an email via phpmailer to a large group of recipients.
I bcc'd the entire group which of course failed after the max limit was reached so I thought what about sending in chunks....
Im just trying to figure out how to loop through the groups of bcc's
basically Im thinking something like this...
$mail = new PHPMailer(true); $mail->IsSMTP(); //setup from, replyto etc here... //email query here to get emails in array $bccz.. //chunk results $newArray = array_chunk($bccz, 50, false); // Now process array_chunk() $i = 0; foreach ($newArray as $inner_array) { $i++; while (list($key, $value) = each($inner_array)) { addBCC($value['email']); }$subject = '=?UTF-8?B?'.base64_encode($cobig).'?='; $mail->Subject = $subject; $mail->IsHTML(true); $mail->Body = $ermail; $mail->Send(); } $mail->clearBcc(); }Just wondering if someone can tell me if this basic logic is right? I have started a project using laravel. I am in the process of builing User groups and permissions in the admin dashboard.
I have uploaded a snapshot of my views to which i want to restrict access. i want to structure it to be completely dynamic
views.PNG 9.41KB
0 downloads
Hey all, I'm wondering the best way to use foreach to break a list of records into groups. For example, the problem with this: Code: [Select] foreach($vanity_url as $v){ if($v->approved){ echo "Approved vanity urls:"; echo $v->url; } else { echo "Unapproved vanity urls:"; echo $v->url; } } is it will return this: Code: [Select] Approved vanity urls: michellefrancis Unapproved vanity urls: johnmerlino Unapproved vanity urls: ericmayers when I want it to return this: Code: [Select] Approved vanity urls: michellefrancis Unapproved vanity urls: johnmerlino ericmayers thanks for response What I am looking for is a small script that works in the way that http://www.groupsort.com/ works. This is for a sports organization. Loads of registrations entered into a MySQL database which need to be automatically sorted into classes that have already been created with an age range specified (Class: S1, From: 1997, To: 1999, Sex: Mixed) Whereas there are some classes with the same set of rules, I have no idea of how I should divide the correct amount of children into correct classes. Can you help? I have a form on a PHP page which has 11 groups of radio buttons. Is there way to use PHP instead of client-side JavaScript to submit the form values only when one radio button has been selected from each of the 11 groups? Also, is it possible to get the form elements in a PHP page with JavaScript? Why does this JavaScript: Code: [Select] myForm.elements.lengthstop working in a PHP page? I thought it wouldn't affect client-side JS since PHP is server-side code. Thank you! Hi all, It's probably something obvious, but perhaps someone could explain to me what is going on here... I spent a lot of time this afternoon trying to fix what seemed to be a very odd problem, which involved an image being chucked out like so: Code: [Select] <?php header("Content-Type: image/png"); echo file_get_contents("http://www.example.com/some_image.png"); ?> Except the image was coming out as corrupted, ultimately because I had some white space before this snippet (foolish, I know). The reason it took me so long to diagnose the problem was because I wasn't getting PHP errors (even though they were switched on). As far as the script was concerned, it seems I wasn't sending anything before attempting to modify the headers. After solving the problem, I put the following little bit of code together, trying to force a header error... And yet I get nothing. It all works, and I get redirected, when I'm sure I shouldn't be. I've run this on a default install of XAMPP, and a configured CentOS server, and the same thing happens on both. If anyone can explain to me what is going on, I would be most appreciative! There are some inline comments which should help clarify what I mean. Code: [Select] <?php error_reporting(E_ALL); ini_set("display_errors","1"); ?> <p>Hello! The very existence of this text should really have resulted in the headers being sent... Shouldn't it?</p> <p>So I'd expect to see a "Headers already sent" message... Shouldn't I?</p> <?php // Headers sent? echo "<p>"; echo "Headers "; if(!headers_sent()) { echo "not "; // This "not" does echo out. } echo "sent.</p>"; // This WILL start a session (or at least, won't throw an error) session_start(); // This redirect WILL work, and you will never see the above messages. header("Location: redirect.php"); // What?! ?> Thanks! Dave Okay, I've read all the rules for Headers...still can't it to execute properly. At the bottom is my code. I basically want to check the database, see if the user is already registered, and redirect as appropriate (there is no HTML on my page, no info sent to the browser). My server doesn't send any error messages. All I get are white screens. Now, if I do the headers_sent()...it tells me that it's sent right after the initial connection with the database. The ONLY way I can get it to redirect, is if I put <?php header("location:index.php?msg=3"); ?> at hte very top, but then I can't evalute...which doesn't help me much. Here is the code (obviously, I have more...but it's sending headers in these lines) <?php $connection = mysql_connect("localhost","####","#####"); if (!$connection){ echo mysql_errno().": ".mysql_error()."<br/>"; exit; } if(!mysql_select_db("prixaurora")){ echo("Database not found<br>"); } My error: Code: [Select] Warning: Cannot modify header information - headers already sent by (output started at /www/zxq.net/w/e/b/webaskius/htdocs/index.php:7) in /www/zxq.net/w/e/b/webaskius/htdocs/functions.php on line 6 Now, I can't quite figure out why it's doing this. The section of code that is causing this problem is above any HTML tags, at the very beginning of the file. <?php include('functions.php'); ?> <link href="style.css" rel="stylesheet" type="TEXT/CSS"> <img src="logo.png" border="0"> <div id="maincontent"> As you can see, the functions that cause this error are at the VERY beginning of my file. This is where they are called within index.php: if(mysql_num_rows($query_verify_login) > 0) { create_cookie(10000, 'user', $username); redirect('index.php'); } else { echo 'Woops! You\'ve entered in the wrong username and password combination!'; } And finally, my functions: <?php //our cookie creator function function create_cookie($time, $name, $data) { setcookie($name, $data, time()+$time); } function redirect($url) { header('Location: '. $url .''); } function get_replies($id) { //set query to find posts that match our id $query_get_replies = mysql_query("SELECT * FROM replies WHERE to = {$id}"); return mysql_num_rows($query_get_replies); } ?> I am trying to do a page redirect using the header() function.
I am aware that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
and also that reading code with include, or require, functions, or another file access function, can create spaces or empty lines that are output before header() is called. thus causing a redirect failure.
I have therefore used this output control function (ob_start(); ob_implicit_flush() right at the top of my page.
I am then creating the redirect like this as part of my login() function:
if($user_role == ADMIN_LEVEL || $user_role == EDITOR_LEVEL) { if (!headers_sent($filename, $linenum)) { return header("Location:http://mysite.com/dashboard.php"); exit; } else { echo "Headers already sent in $filename on line $linenum\n" . "Cannot redirect\n"; exit; } }Unfortunately I am still getting this error: Headers already sent in /home/steveoje/public_html/login.php on line 1 Cannot redirectAnd this is what I have at the top of the login.php page: <?php ob_start(); ob_implicit_flush(); require_once 'includes/config.php'; if(isset($_POST['submit'])) { login($_POST['username'], $_POST['password']); } require_once "includes/header.inc.php" ?> //other html contentSo why would the redirect fail in this instance? Thanks. Edited by terungwa, 28 September 2014 - 05:28 AM. I have a form as a php include and it's giving me this error: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/altimusw/public_html/www.csmsolution.com/register.php:6) in /home/altimusw/public_html/www.csmsolution.com/core.php on line 17 Here is the main page that includes the php include: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>CSM Solution </title> <style type="text/css"> <!-- #Layer1 { position:absolute; left:100px; top:70px; width:800; height:62px; z-index:1; } .style1 { font-family: Arial, Helvetica, sans-serif; color: #535959; font-size: 12px; } --> </style> </head> <body> <div id="Layer1"> <table width="800" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="97"><img src="images/header.jpg" width="800" height="59" border="0" usemap="#Map" /><br /> <img src="images/navbar.jpg" width="800" height="38" border="0" usemap="#Map2" /> <map name="Map2" id="Map2"> <area shape="rect" coords="506,1,552,26" href="contact.php" /><area shape="rect" coords="459,1,502,26" href="form.php" /><area shape="rect" coords="396,-1,455,25" href="login.php" /> <area shape="rect" coords="357,0,393,26" href="index.php" /> </map> </td> </tr> <tr> <td><img src="images/welcome_img.jpg" width="131" height="21" /></td> </tr> <tr> <td><?php include("form.php"); ?></td> </tr> <tr> <td><img src="images/placeholderclouds_bottem.jpg" width="800" height="60" /></td> </tr> </table> </div> </body> </html> Here is the Core.php the error is referring to: <?php //CSM Solution Core. Rahul Parkar 2010 $_config = array(); $_config['db_type'] = "mysql"; $_config['db_server'] = "localhost"; $_config['db_username'] = "altimusw_csm"; $_config['db_password'] = ']17=rXh7tJ0~'; $_config['db_database'] = "altimusw_csm"; $_config['db_tbl_prefix'] = ''; $_config['user_table'] = "customers"; $_config['user_username'] = "username"; $_config['user_password'] = "password"; $_config['user_active'] = "approved"; $_config['user_role1'] = "prirole"; $_config['user_role2'] = "secrole"; $_config['pass_hash_func'] = "SHA1"; session_start(); function fetch_row($query) { build_connection($db); sql_exec($db, $query, $result); sql_fetchone($result, $row); finish_connection($db); return $row; } function build_connection(&$db) { global $_config; if ($_config['db_type'] == "mysql") { $db = mysql_connect($_config['db_server'], $_config['db_username'], $_config['db_password']) or die(mysql_error()); mysql_select_db($_config['db_database'], $db) or die(mysql_error()); } } function sql_exec(&$db, $query, &$result) { global $_config; if ($_config['db_type'] == "mysql") $result = mysql_query($query, $db) or die(mysql_error() . "/$query"); } function sql_fetchone(&$result, &$row) { global $_config; if ($_config['db_type'] == "mysql") { $row = mysql_fetch_assoc($result); @mysql_free_result($result); } } function sql_do(&$db, $query) { global $_config; sql_exec($db, $query, $noclue); finish_connection($db); } function finish_result(&$result) { global $_config; if ($_config['db_type'] == "mysql") @mysql_free_result($result); } function finish_connection(&$db) { global $_config; if ($_config['db_type'] == 'mysql') mysql_close($db); } function check_auth($username, $password) { global $_config; $row = fetch_row("SELECT `" . $_config['user_active'] . "`, `" . $_config['user_password'] . "`, " . $_config['pass_hash_func'] . "('" . $password . "') AS `passcheck`, `fname`, `lname` FROM `" . $_config['user_table'] . "` WHERE `" . $_config['user_username'] . "`='" . $username . "' LIMIT 1"); if (!$row[$_config['user_active']]) { return -1; } else { if ($row[$_config['user_active']] != 1) { return -2; } else if ($row[$_config['user_password']] == $row['passcheck']) { $_SESSION['username'] = $username; $_SESSION['fname'] = $row['fname']; $_SESSION['lname'] = $row['lname']; return 1; } else { return -1; } } } function load_access() { global $_config; if ($_SESSION['username']) { $row = fetch_row("SELECT `" . $_config['user_role1'] . "` FROM `" . $_config['user_table'] . "` WHERE `" . $_config['user_username'] . "`='" . $_SESSION['username'] . "' LIMIT 1"); $role1 = $row[$_config['user_role1']]; $_SESSION['role1'] = $role1; } else { return -1; } } function has_level() { for ($i = 0; $i < func_num_args(); $i++) { if (func_get_arg($i) == $_SESSION['role1']) { return 1; } } return 0; } ?> |