Jump to content

jcbones

Staff Alumni
  • Posts

    2,653
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by jcbones

  1. You need to re-think your logic. The way you are building your array is going to make it next to impossible to accomplish your task. I would make two arrays. while($row = mysql_fetch_assoc($result)) { if($row['parent'] == 0) { $parent_array[$row['idd']] = $row['titre1']; } //Parent array = array( id => name); else { $child_array[$row['parent']][$row['idd']] = $row['titre1']; } //Child array = array(parent_id => array(id => name, id => name)); } foreach($parent_array as $p_id => $p_name) { echo $p_name . '<div>'; foreach($child_array as $p_link => $L2) { if($p_link == $p_id) { foreach($L2 as $c_id => $c_name) { echo $c_id . ' ' . $c_name . '<br />' . "\n"; } } } echo '</div>'; } *code un-tested*
  2. I would have suggested. $search_term = 'California'; $abbr = array_keys($states_arr,$search_term); echo $abbr[0]; This would run at runtime, I don't know if I would change all of those columns. If I wanted to input them into the Base, I would add a column.
  3. Try: if(!in_array($res->year(),$arr)) //if $res->year() is not in the array of $arr.
  4. Or, a quick google returned http://www.google.com/search?q=php+virtual+airlines+cms I would suggest visiting the first link. As it seems to do what you want.
  5. Try your database insert as: $sql="INSERT INTO gallery (Name,PicAddress,Category) VALUES ('$Name','Graphics/$Pic','$Category')"; The ../ may be messing this up. Not for certain. ../ in a url drops the previous directory. If your gallery resides at http://mysite.com/gallery.php, then it will look for the pics at http://mysite.com/Graphics/pics.jpg. But, if you gallery resides at http://mysite.com/gallery/gallery.php, then it will look for the pics at http://mysite.com/Graphics/pics.jpg.
  6. If you are using mysql_real_escape_string() there is no need to addslashes. Trim takes away whitespace from the ends, and strip_tags strips out any HTML. If you are checking by regex, you could eliminate all three of those functions. $pattern = '~[^A-Za-z]~'; //Allow only alpha characters. This gets rid of whitespace, or HTML brackets, or quotes, commas, dashes, etc. $name = preg_replace($pattern,'',$_POST['name']); Lastly, I would pass it through mysql_real_escape_string(). This will add slashes for the DB, just like you stated.
  7. In your example $arr has nothing to do with the foreach loop. AS the foreach loop is running the array of $results.
  8. The (~) is de-limiters, It is like yours except you are using slashes. Only when delimiting the slashes, you must escape the escaping slash. Just adds more slashes, like (\\{). I'm probably not being clear. Explanation of the string. ~ delimiter ^ matches beginning of string [] encloses a set. a-z matches any lowercase alpha character A-Z matches any uppercase alpha character \s matches any space _ matches any underscore \- matches any dash + matches 1 or more of the previous expression $ matches the end of the string ~ ending delimiter.
  9. Try: RewriteRule ^profile/username/(.*).html$ profile.php?username=$1 Or, RewriteRule ^profile/(.*)/(.*).html$ profile.php?$1=$2
  10. Escape them with a slash ( \ ). If you are going to that trouble, why not just check to see if the string contains only alphaNumeric + underscore and dashes. $pattern = '~^[a-zA-Z0-9\s_\-]+$~'; //Matches any string with spaces, underscore, dashes, or alphanumeric.
  11. You should be able to use: $sql = "DELETE `users`,`user_profiles` FROM `users` INNER JOIN `user_profiles` WHERE `users`.`userID` = `user_profiles`.`userID` AND `users`.`status` = 'inactive'"; MySQL DELETE Syntax NOTICE* This code is un-tested.
  12. At the very bottom, you can echo out a string. <?php ++$i; } echo 'Emails has been sent.'; ?> If you prefer a pop up box: <?php ++$i; } ?> <script type="text/javascript"> alert('Emails Sent!'); </script>
  13. member_group assigns the name "Members","Non-Members","Undefined". total_count assigns the number for each. The database will return 3 rows. Row 1: Members(member_group) , *number*(total_count) Row 2: Non-Members(member_group), *number*(total_count) Row 3: Undefined(member_group), *number*(total_count). To subtract 2. $totalcount = ($row['member_group'] == 'Members') ? $row['total_count'] - 2 : $row['total_count']; echo $row['member_group'] . ' ' . $totalcount . '<br />';
  14. Suppresses error notifications. IMO it should be used sparingly, or not at all. The only time I use it is for arrays where the key's are dynamic, and I'm adding them together in a while loop. Other than that, define your variables, and don't divide by 0. Then you won't need them.
  15. You need to close it up. </textarea>
  16. Ignace gave the most appropriate answer, and I can help you with the coding. $sql = "SELECT (CASE activate WHEN 'y' THEN 'Members' WHEN 'n' THEN 'Non-Members' ELSE 'Undefined' END) AS member_group, count(*) AS total_count FROM customers GROUP BY activate"; $result = mysql_query($sql); // Print out result while($row = mysql_fetch_array($result)) { echo "There are ". $row['total_count'] ." " . $row['member_group'] . "<br/>\n"; echo "<br />"; } Should spit it right out to you.
  17. I would save the image path to the database, instead of the image itself. But, if you are going to store the image to the database, why do you need to store it to the server. Just encode it from the $_FILES['image']['tmp_name']. Is your form enctype set? <form action="" method="post" enctype="multipart/form-data"> This would be the only reason I could think that the form would submit text and not files.
  18. JOIN websites ON websites.userid = users.id You are joining the tables by selecting the website's userid (equal to) the users' userid. Now I'm not sure what the userid column in the website table is suppose to be used for. But, using it this way is limiting each website to only be used by one individual user.
  19. Let me get this straight. It is working, but the rows are limited to 1 of 4, instead of correctly being 1 of 10? Did you run the query through MySQL sans the LIMIT 1 and see what was returning?
  20. Well, I should have done this the first time: Full commented script: <?php include('config.php'); //This function returns a percentage, nothing more. function percentage($low, $high) { return number_format(($low / $high)*100,1); //the last number sets how many spaces after the decimal to return. } //SQL query, only need one, we are processing the data with an array. $getsalesrep = "SELECT * FROM efi_customers_test WHERE cms_type = 'Booking' AND Date BETWEEN '2009-03-24' AND '2010-04-24'"; //DEBUG, un-comment the next line; //echo $getsalesrep; //Run the query, or die trying. $resultsalesrep = mysql_query($getsalesrep) or die(mysql_error()); //Loop through the data. while ($row = mysql_fetch_array($resultsalesrep)){ //Set an array for the sales people. I tried doing it with only one array //But, alas, you wanted them all on the top row. No problems. $people[] = $row['salesperson']; //Set another array holding the rest of the data, and tying it in with the //sales person. The @ just suppresses the notice the variable gives on it's //creation, since it wasn't set before. @$sales[$row['FundraiserName']][$row['salesperson']][$row['booked']] += 1; } //Now the $people array will have multiple people in it, so we need to get //only one instance of a persons name. array_unique() does that, but then //we need to run array_values() to get the key's to line up for a for loop. $people = array_values(array_unique($people)); //Store the number of salespeople in $count. $count = count($people); //DEBUG un-comment next line. //echo '<pre>'; print_r($sales); echo '</pre>'; //Start our table. echo '<table><tr><td style="font-weight: bold;">Fundraisers</td>' . "\n"; //is_array just makes sure $people is an array. if(is_array($people)) { //loop through the array, and echo the salespeople. foreach($people as $salesperson) { echo '<td colspan="3">'. $salesperson . '</td>' . "\n"; } echo '<td colspan="3">TOTAL</td></tr>'; } //just checking the sales array. if(is_array($sales)) { //Now things get interesting. Looping through the sales array. foreach($sales as $fundraiser => $v2) { //echo our the fundraiser. echo '<tr><td>' . $fundraiser . '</td>'; //These next 3 variables will set/reset to 0 on each loop. $totalBooking = 0; $totalBooked = 0; $totalPercentage = 0; //Running a for loop, This is because we need to cycle through the //people array, and pull data so it is lined up with the sales person //at the top of the current column. for($i = 0; $i < $count; $i++) { //IN DEPTH: $people[$i] will pass the name of the salesperson at the top of the current column //so that we can make sure the columns will line up right. //------------------------------------ //might need to edit the line below, as I know that $row['booked'] could hold 'checked', I don't know if the other value is null, or 'not checked'. $bookings = (isset($sales[$fundraiser][$people[$i]]['']) && isset($sales[$fundraiser][$people[$i]]['checked'])) ? $sales[$fundraiser][$people[$i]][''] + $sales[$fundraiser][$people[$i]]['checked'] : 0; //------------------------------------ $booked = (isset($sales[$fundraiser][$people[$i]]['checked'])) ? $sales[$fundraiser][$people[$i]]['checked'] : 0; //Get the percentage from the function at the top of the page. $percentage = percentage($booked,$bookings); //echo the findings out. echo '<td>'. $bookings . '</td><td>'. $booked. '</td><td>'. $percentage . '%</td>'; //add the bookings/booked together so we can write them to the end of this row. $totalBooking += $bookings; $totalBooked += $booked; //now add the bookings/booked to an array, using the column number to keep `em straight. @$vert[$i]['booking'] += $bookings; @$vert[$i]['booked'] += $booked; } //echo out the total column for this row. Again using percentage function from the top of the page. echo '<td>'. $totalBooking. '</td><td>'. $totalBooked. '</td><td>'. percentage($totalBooked,$totalBooking). '%</td></tr>'; //counting the totals for the final row's last column. $totalBooking, and $totalBooked will be reset on the next loop. @$totalTotalBooking += $totalBooking; @$totalTotalBooked += $totalBooked; } } //echo'ing the last row. echo '<tr><td>TOTALS</td>'; if(is_array($vert)) { //Run a for loop to line up the columns correctly. Again using percentage function at top of page. for($i = 0; $i < $count; $i++){ echo '<td>'. $vert[$i]['booking']. '</td><td>'. $vert[$i]['booked'] . '</td><td>'. percentage($vert[$i]['booked'],$vert[$i]['booking']) . '%</td>'; } } //echo out the last column of the last row, we kept count of it at the end of each loop above. echo '<td>'. $totalTotalBooking. '</td><td>'. $totalTotalBooked . '</td><td>'. percentage($totalTotalBooked,$totalTotalBooking). '% </tr> </table>'; ?>
  21. In JonsJava's example, the echo should be. echo "<li> <a href=\"suggest.php?mid=".$results->imdbid()."\">".$results->title()." (".$results->year()."</a></li>"; Dunno if that helps, or not.
  22. That is Var's that have been passed to the current page, using a form with those var's in hidden inputs pass' them to the next page.
  23. I'll leave this as a note to the last question: Ajax Tutorial
  24. ccchan, I was somewhat bored today, and decided to try and sort through this code. It seemed somewhat confusing, so I wrote a version for you to study. This attempts to do what you are trying to do, with a lot less code. It probably isn't what you are looking for, but it isn't suppose to be. Merely an example of processing an array. <?php include('config.php'); function percentage($low, $high) { return number_format(($low / $high)*100,1); //the last number sets how many spaces after the decimal to return. } $getsalesrep = "SELECT * FROM efi_customers_test WHERE cms_type = 'Booking' AND Date BETWEEN '2009-03-24' AND '2010-04-24'"; //echo $getsalesrep; $resultsalesrep = mysql_query($getsalesrep) or die(mysql_error()); while ($row = mysql_fetch_array($resultsalesrep)){ $people[] = $row['salesperson']; @$sales[$row['FundraiserName']][$row['salesperson']][$row['booked']] += 1; } $people = array_values(array_unique($people)); $count = count($people); //echo '<pre>'; print_r($sales); echo '</pre>'; echo '<table><tr><td style="font-weight: bold;">Fundraisers</td>' . "\n"; if(is_array($people)) { foreach($people as $salesperson) { echo '<td colspan="3">'. $salesperson . '</td>' . "\n"; } echo '<td colspan="3">TOTAL</td></tr>'; } if(is_array($sales)) { foreach($sales as $fundraiser => $v2) { echo '<tr><td>' . $fundraiser . '</td>'; $totalBooking = 0; $totalBooked = 0; $totalPercentage = 0; for($i = 0; $i < $count; $i++) { //------------------------------------ //might need to edit the line below, as I know that $row['booked'] could hold 'checked', I don't know if the other value is null, or 'not checked'. $bookings = (isset($sales[$fundraiser][$people[$i]]['']) && isset($sales[$fundraiser][$people[$i]]['checked'])) ? $sales[$fundraiser][$people[$i]][''] + $sales[$fundraiser][$people[$i]]['checked'] : 0; //------------------------------------ $booked = (isset($sales[$fundraiser][$people[$i]]['checked'])) ? $sales[$fundraiser][$people[$i]]['checked'] : 0; $percentage = percentage($booked,$bookings); echo '<td>'. $bookings . '</td><td>'. $booked. '</td><td>'. $percentage . '%</td>'; $totalBooking += $bookings; $totalBooked += $booked; @$vert[$i]['booking'] += $bookings; @$vert[$i]['booked'] += $booked; } echo '<td>'. $totalBooking. '</td><td>'. $totalBooked. '</td><td>'. percentage($totalBooked,$totalBooking). '%</td></tr>'; @$totalTotalBooking += $totalBooking; @$totalTotalBooked += $totalBooked; } } echo '<tr><td>TOTALS</td>'; if(is_array($vert)) { for($i = 0; $i < $count; $i++){ echo '<td>'. $vert[$i]['booking']. '</td><td>'. $vert[$i]['booked'] . '</td><td>'. percentage($vert[$i]['booked'],$vert[$i]['booking']) . '%</td>'; } } echo '<td>'. $totalTotalBooking. '</td><td>'. $totalTotalBooked . '</td><td>'. percentage($totalTotalBooked,$totalTotalBooking). '% </tr> </table>'; ?>
  25. You could also do it in a link. <a href="url?id=<?php echo $id; ?>" onclick"return confirm('Are you sure you wish to delete?');">Remove</a>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.