Jump to content

karenn1

Members
  • Posts

    177
  • Joined

  • Last visited

    Never

About karenn1

  • Birthday 02/23/1984

Profile Information

  • Gender
    Female
  • Location
    South Africa

karenn1's Achievements

Member

Member (2/5)

0

Reputation

  1. Hey everyone, I hope someone can help me. I have a form with a table like this: <table width="850" border="0" align="left" cellpadding="5" cellspacing="0" id="mytable"> <tr> <td width="5%" align="left"><strong>Date</strong></td> <td width="21%" align="left"><input name="admission-date[]" id="admission-date" size="15"/></td> <td width="10%" align="left"><strong>Hospital</strong></td> <td width="16%" align="left"><input name="admission-hospital[]" id="admission-hospital" type="text" size="15" /></td> <td width="8%" align="left"><strong>Doctor </strong></td> <td width="17%" align="left"><input name="admission-doctor[]" id="admission-doctor" type="text" size="15" /></td> <td width="8%" align="left"><strong>Details</strong></td> <td width="15%" align="left"><input name="admission-details[]" id="admission-details" type="text" size="15" /></td> </tr> </table> And this is the PHP to store the info: //multiple entries for admission history //admission-date $array1 = $_POST["admission-date"]; $counter1 = 0; $string_to_db1 = ""; $separator1 = ""; foreach($array1 as $item1){ if($counter1 <> 0) { $separator1 = "|"; } $string_to_db1 .= "$separator1$item1"; ++$counter1; } /////// //admission-hospital $array2 = $_POST["admission-date"]; $counter2 = 0; $string_to_db2 = ""; $separator2 = ""; foreach($array2 as $item2){ if($counter2 <> 0) { $separator2 = "|"; } $string_to_db2 .= "$separator2$item2"; ++$counter2; } /////// //admission-doctor $array3 = $_POST["admission-doctor"]; $counter3 = 0; $string_to_db3 = ""; $separator3 = ""; foreach($array3 as $item3){ if($counter3 <> 0) { $separator3 = "|"; } $string_to_db3 .= "$separator3$item3"; ++$counter3; } /////// //admission-details $array4 = $_POST["admission-details"]; $counter4 = 0; $string_to_db4 = ""; $separator4 = ""; foreach($array4 as $item4){ if($counter4 <> 0) { $separator4 = "|"; } $string_to_db4 .= "$separator4$item4"; ++$counter4; } /////// I've used jQuery to add a row to the table by clicking on a Plus sign. All of this works perfectly and the data is stored separated with a pipe, ie. 2012-08-12|2012-08-21, etc. The issue I'm having is pulling this back into a page where it can be edited. I'm thinking of using explode but I don't know how to get the table layout as I had it originally as shown above. How do I get it to loop as such and have the label next to the value? Thanks in advance, Karen
  2. Something like that, yes. But my boss just came in and changed the spec so I don't need it anymore. Thanks for your help anyway! Karen
  3. AWESOME!! Thanks @gristoi, that works perfectly. I need more help though. In the same table that stores the dates, I have a user ID attached to each date. I would like to change the highlight colour for each user ID. Here's the code. Would this be possible? <?php /** * Calendar Generation Class * * This class provides a simple reuasable means to produce month calendars in valid html * * @version 2.8 * @author Jim Mayes <jim.mayes@gmail.com> * @link http://style-vs-substance.com * @copyright Copyright (c) 2008, Jim Mayes * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt GPL v2.0 */ class Calendar{ var $date; var $year; var $month; var $day; var $week_start_on = FALSE; var $week_start = 7;// sunday var $link_days = TRUE; var $link_to; var $formatted_link_to; var $mark_today = TRUE; var $today_date_class = 'today'; var $mark_selected = TRUE; var $selected_date_class = 'selected'; var $mark_passed = TRUE; var $passed_date_class = 'passed'; var $highlighted_dates; var $default_highlighted_class = 'highlighted'; /* CONSTRUCTOR */ function Calendar($date = NULL, $year = NULL, $month = NULL){ $self = htmlspecialchars($_SERVER['PHP_SELF']); $this->link_to = $self; if( is_null($year) || is_null($month) ){ if( !is_null($date) ){ //-------- strtotime the submitted date to ensure correct format $this->date = date("Y-m-d", strtotime($date)); } else { //-------------------------- no date submitted, use today's date $this->date = date("Y-m-d"); } $this->set_date_parts_from_date($this->date); } else { $this->year = $year; $this->month = str_pad($month, 2, '0', STR_PAD_LEFT); } } function set_date_parts_from_date($date){ $this->year = date("Y", strtotime($date)); $this->month = date("m", strtotime($date)); $this->day = date("d", strtotime($date)); } function day_of_week($date){ $day_of_week = date("N", $date); if( !is_numeric($day_of_week) ){ $day_of_week = date("w", $date); if( $day_of_week == 0 ){ $day_of_week = 7; } } return $day_of_week; } function output_calendar($year = NULL, $month = NULL, $calendar_class = 'calendar'){ if( $this->week_start_on !== FALSE ){ echo "The property week_start_on is replaced due to a bug present in version before 2.6. of this class! Use the property week_start instead!"; exit; } //--------------------- override class methods if values passed directly $year = ( is_null($year) )? $this->year : $year; $month = ( is_null($month) )? $this->month : str_pad($month, 2, '0', STR_PAD_LEFT); //------------------------------------------- create first date of month $month_start_date = strtotime($year . "-" . $month . "-01"); //------------------------- first day of month falls on what day of week $first_day_falls_on = $this->day_of_week($month_start_date); //----------------------------------------- find number of days in month $days_in_month = date("t", $month_start_date); //-------------------------------------------- create last date of month $month_end_date = strtotime($year . "-" . $month . "-" . $days_in_month); //----------------------- calc offset to find number of cells to prepend $start_week_offset = $first_day_falls_on - $this->week_start; $prepend = ( $start_week_offset < 0 )? 7 - abs($start_week_offset) : $first_day_falls_on - $this->week_start; //-------------------------- last day of month falls on what day of week $last_day_falls_on = $this->day_of_week($month_end_date); //------------------------------------------------- start table, caption $output = "<table class=\"" . $calendar_class . "\">\n"; $output .= "<caption>" . ucfirst(strftime("%B %Y", $month_start_date)) . "</caption>\n"; $col = ''; $th = ''; for( $i=1,$j=$this->week_start,$t=(3+$this->week_start)*86400; $i<=7; $i++,$j++,$t+=86400 ){ $localized_day_name = gmstrftime('%A',$t); $col .= "<col class=\"" . strtolower($localized_day_name) ."\" />\n"; $th .= "\t<th title=\"" . ucfirst($localized_day_name) ."\">" . strtoupper($localized_day_name{0}) ."</th>\n"; $j = ( $j == 7 )? 0 : $j; } //------------------------------------------------------- markup columns $output .= $col; //----------------------------------------------------------- table head $output .= "<thead>\n"; $output .= "<tr>\n"; $output .= $th; $output .= "</tr>\n"; $output .= "</thead>\n"; //---------------------------------------------------------- start tbody $output .= "<tbody>\n"; $output .= "<tr>\n"; //---------------------------------------------- initialize week counter $weeks = 1; //--------------------------------------------------- pad start of month //------------------------------------ adjust for week start on saturday for($i=1;$i<=$prepend;$i++){ $output .= "\t<td class=\"pad\"> </td>\n"; } //--------------------------------------------------- loop days of month for($day=1,$cell=$prepend+1; $day<=$days_in_month; $day++,$cell++){ /* if this is first cell and not also the first day, end previous row */ if( $cell == 1 && $day != 1 ){ $output .= "<tr>\n"; } //-------------- zero pad day and create date string for comparisons $day = str_pad($day, 2, '0', STR_PAD_LEFT); $day_date = $year . "-" . $month . "-" . $day; //-------------------------- compare day and add classes for matches if( $this->mark_today == TRUE && $day_date == date("Y-m-d") ){ $classes[] = $this->today_date_class; } if( $this->mark_selected == TRUE && $day_date == $this->date ){ $classes[] = $this->selected_date_class; } if( $this->mark_passed == TRUE && $day_date < date("Y-m-d") ){ $classes[] = $this->passed_date_class; } if( is_array($this->highlighted_dates) ){ if( in_array($day_date, $this->highlighted_dates) ){ $classes[] = $this->default_highlighted_class; } } //----------------- loop matching class conditions, format as string if( isset($classes) ){ $day_class = ' class="'; foreach( $classes AS $value ){ $day_class .= $value . " "; } $day_class = substr($day_class, 0, -1) . '"'; } else { $day_class = ''; } //---------------------------------- start table cell, apply classes // detect windows os and substitute for unsupported day of month modifer $title_format = (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')? "%A, %B %#d, %Y": "%A, %B %e, %Y"; $output .= "\t<td" . $day_class . " title=\"" . ucwords(strftime($title_format, strtotime($day_date))) . "\">"; //----------------------------------------- unset to keep loop clean unset($day_class, $classes); //-------------------------------------- conditional, start link tag switch( $this->link_days ){ case 0 : $output .= $day; break; case 1 : if( empty($this->formatted_link_to) ){ $output .= "<a href=\"" . $this->link_to . "?date=" . $day_date . "\">" . $day . "</a>"; } else { $output .= "<a href=\"" . strftime($this->formatted_link_to, strtotime($day_date)) . "\">" . $day . "</a>"; } break; case 2 : if( is_array($this->highlighted_dates) ){ if( in_array($day_date, $this->highlighted_dates) ){ if( empty($this->formatted_link_to) ){ $output .= "<a href=\"" . $this->link_to . "?date=" . $day_date . "\">"; } else { $output .= "<a href=\"" . strftime($this->formatted_link_to, strtotime($day_date)) . "\">"; } } } $output .= $day; if( is_array($this->highlighted_dates) ){ if( in_array($day_date, $this->highlighted_dates) ){ if( empty($this->formatted_link_to) ){ $output .= "</a>"; } else { $output .= "</a>"; } } } break; } //------------------------------------------------- close table cell $output .= "</td>\n"; //------- if this is the last cell, end the row and reset cell count if( $cell == 7 ){ $output .= "</tr>\n"; $cell = 0; } } //----------------------------------------------------- pad end of month if( $cell > 1 ){ for($i=$cell;$i<=7;$i++){ $output .= "\t<td class=\"pad\"> </td>\n"; } $output .= "</tr>\n"; } //--------------------------------------------- close last row and table $output .= "</tbody>\n"; $output .= "</table>\n"; //--------------------------------------------------------------- return return $output; } } ?>
  4. Hey everyone! I found a script on the net to display a calendar on my page and it works fine. It has a piece of code where I can specify which dates must be highlighted in a month. It looks like this: $calendar->highlighted_dates = array( '2011-12-03', '2011-12-14', '2011-12-25' ); I've got a list of dates in a table in my database that I need to get into this array. It's formatted the same as in the example. Can someone please help? Thanks, Karen
  5. karenn1

    Find in set

    I actually found something that works well: SELECT * FROM projects WHERE MATCH (project_type) AGAINST ('Agriculture, Environment') This finds all the rows where the project type is Agriculture and/or Environment. Are there any draw backs in using this?
  6. karenn1

    Find in set

    Ok, so I've replaced the semi-colons with commas. @fenway, how can I hack it to make it work? Karen
  7. karenn1

    Find in set

    Hi guys, Thanks for the reply. To answer your question Dan, I quoted a certain amount of time to do a few specific things on this site. Unfortunately, I didn't quote extra to redesign the database and it will take me some time to do. I won't get paid for that time. I understand what you are saying though but in this case, I just can't do it that way. I need to make it work in it's current format. I'll try the REPLACE() and use commas instead and see if that works. Karen
  8. karenn1

    Find in set

    Hey everyone, I have a page where a user can select one or more project types from a multiple select box. When they click on Search, I would like to query a field in the database and return the values that match the search. This is my code: SELECT * FROM projects WHERE FIND_IN_SET('Agriculture,Environment', project_type) If I put in Agriculture on its own, it returns rows. Likewise with Environment so I know there's data for both. but it's not working together. Here's my data structure: id name project_type 1 Project 1 Agriculture 2 Project 2 Agriculture;Environment 3 Project 3 Environment This is how I inherited this database. The project type data is delimited with a semi-colon. Can someone please help? Thanks in advance! Karen
  9. @mjdamato - that's exactly what I was looking for! Works great! Thanks to all for your input! Karen
  10. Thanks, I tried your code but I'm still getting this: Agriculture Agriculture Agriculture Agriculture Agriculture Agriculture Agriculture Agriculture Export Development Agriculture Impact Assessments Impact Studies Agriculture M & E Agriculture Private Sector Development Corporate and Public Governance Corporate and Public Governance Corporate and Public Governance Am I doing something wrong?
  11. Thanks for the reply. @dan - this is not my database. I inherited it from someone else so I need to make it work in its current state. There is no time or budget to rebuild. @muddy_funster - correct. I would like each one to only display once. Any ideas? Regards, Karen
  12. Hey everyone, I have a database for projects and each entry has one or more project type category that it falls into. The values are separated with a semi-colon to make the distinction. I've used the following code to output the data onto the page: $sql = "SELECT project_type FROM projects ORDER BY project_type"; $result = mysql_query($sql); while ($rs = mysql_fetch_array($result)) { $database_value = $rs['project_type']; $array = explode(';', $database_value); foreach($array as $key => $value){ echo " ".$value."<br />"; } } This outputs the following: Agriculture Agriculture Agriculture Agriculture Agriculture Agriculture Agriculture Agriculture Export Development Agriculture Impact Assessments Impact Studies Agriculture M & E Agriculture Private Sector Development Corporate and Public Governance Corporate and Public Governance Corporate and Public Governance In PHP, how can I group these values together, similar to SQL's GROUP BY method? I've tried grouping it in the query but some of the data goes lost because it must be exploded first. Can anybody help? Thanks in advance! Karen
  13. @PFMaBiSmAd, thanks again! I really appreciate your help!!!!! I'll give the WHERE clause a try.
  14. @PFMaBiSmAd, can I ask another question? Everything is working fine. Only thing I encountered is when there is no info for a tender, the table is blank. ie: Subscriber Category Email Tender Info Dummy Company 1 Advertisting email@email.com Tender 1 Dummy Company 1 Promotions email@email.com No current tenders for this category Dummy Company 1 Construction email@email.com No current tenders for this category So, in your coding, it's looping through the rows, but the values are blank. Any way around this? Karen
  15. @PFMaBiSmAd - you are an absolute ROCK STAR!!! The code works perfectly! Thank you SO SO much! I'm thankful there are still people like you around. Blessings! Karen
×
×
  • 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.