Jump to content

FifeBirder

Members
  • Posts

    19
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

FifeBirder's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Blank value in mySQL , no Reset -- Can you explain ?
  2. mjdamato thanks alot for that more elegant solution. I am still digesting it but do get the jist of it. One little problem i have with the drop down box now is that if i select the firt option it does not work, all others do. Any ideas ? regards
  3. mjdamato Working alot better, stable drop downs, but what i am finding is that the drop down box is not showing all selections, it is as if it is missing every second one if that makes sense. The full Alertz_VIP.php is :- <?php /*************************************************************************** * Alertz.php * ------------------- * ***************************************************************************/ define('IN_ICYPHOENIX', true); if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './'); if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1)); // Include files include(IP_ROOT_PATH . 'common.' . PHP_EXT); include_once(IP_ROOT_PATH . 'includes/functions_groups.' . PHP_EXT); include(IP_ROOT_PATH . '/alerts/alertsconfig.'.PHP_EXT); // Page Authorise $cms_page_id = 'scotalertz'; $cms_page_nav = (!empty($cms_config_layouts[$cms_page_id]['page_nav']) ? true : false); $cms_global_blocks = (!empty($cms_config_layouts[$cms_page_id]['global_blocks']) ? true : false); $cms_auth_level = (isset($cms_config_layouts[$cms_page_id]['view']) ? $cms_config_layouts[$cms_page_id]['view'] : AUTH_ALL); check_page_auth($cms_page_id, $cms_auth_level); // Obtain Select Criteria $temp_region_filter = $_GET["REGION_FILTER"]; $temp_species_filter = $_GET["SPECIES_FILTER"]; $temp_date_filter = $_GET["DATE_FILTER"]; // Filter characters if required $region_filter =str_replace(" & ", "&", $temp_region_filter); $species_filter = $temp_species_filter; $date_filter = $temp_date_filter; // standard session management $userdata = session_pagestart($user_ip); // Check to see if user is logged in if ((!$userdata['session_logged_in']) ) // No he isnt { redirect(append_sid(LOGIN_MG . '?redirect=alerts.' . PHP_EXT)); } else // Yes they are { init_userprefs($userdata); // set page title $page_title = "ScotBird alerts - VIP's ONLY !! "; // standard page header include(IP_ROOT_PATH . 'includes/page_header.'.PHP_EXT); // Connect to the database $db = new sql_db($alerts_mysql_host,$alerts_mysql_username,$alerts_mysql_password,$alerts_mysql_db,false); if(!$db) { die("Database Connection Failed:- Please Contact Site Admin" . mysql_error()); } $template->set_filenames(array('body' => 'alertz_VIP.tpl')); // Some consistant Variables $year =date("Y"); $month = date("m"); $day = date("d"); function datedropdown_funct($switchstring) { $year =date("Y"); $month = date("m"); $day = date("d"); switch ($switchstring) { case "Today": $day = date("d")-1; $retval = '<option value="">Select</option><option value="Today" SELECTED>Today</option><option value="Last 48hrs">Last 48hrs</option><option value="Last week">Last Week</option><option value="last month">Last Month</option>'; break; case "Last 48hrs": $day = date("d")-2; $retval = '<option value="">Select</option><option value="Today">Today</option><option value="Last 48hrs" SELECTED>Last 48hrs</option><option value="Last week">Last Week</option><option value="last month">Last Month</option>'; break; case "Last week": $day = date("d")-8; $retval = '<option value="">Select</option><option value="Today">Today</option><option value="Last 48hrs">Last 48hrs</option><option value="Last week" SELECTED>Last Week</option><option value="last month">Last Month</option>'; break; case "last month": $month = date("m")-2; $retval = '<option value="">Select</option><option value="Today">Today</option><option value="Last 48hrs">Last 48hrs</option><option value="Last week">Last Week</option><option value="last month" SELECTED>Last Month</option>'; break; case "last 3 months": $month = date("m")-4; $retval = '<option value="">Select</option><option value="Today">Today</option><option value="Last 48hrs">Last 48hrs</option><option value="Last week">Last Week</option><option value="last month">Last Month</option><option value="last 3 months" SELECTED>Last 3 Month</option>'; break; default: // Default is the last 48hrs $day = date("d")-1; } $thestartdatecalc = $year . '-' .$month . '-' . $day ; echo $thestartdate; return array($retval, $thestartdatecalc); } $theenddate = $year . '-' .$month . '-' . $day ; // Check if the Date is Set if(isset($date_filter) and strlen($date_filter) > 0) { // The date is Set echo "Date is Set :- " . $date_filter . " - "; // Check to see if Region is set if(isset($region_filter) and strlen($region_filter) > 0) { // The region is set echo "Region is Set :- " . $region_filter . " - "; // Check to see if species is set if(isset($species_filter) and strlen($species_filter) > 0) { // The species is set echo "Species is Set :- " . $species_filter . " - "; list($arr1, $arr2) = datedropdown_funct($date_filter); $date_filter_options= $arr1; $thestartdate.= $arr2; $sql2 = "SELECT * FROM alerts WHERE Date BETWEEN '".$thestartdate ."' AND '".$theenddate ."' AND region = '".$region_filter ."' AND species = '".$species_filter ."' ORDER BY Date DESC, time DESC "; $sql3 = "SELECT DISTINCT species FROM alerts WHERE Date BETWEEN '".$thestartdate ."' AND '".$theenddate ."' AND region = '". $region_filter . "' GROUP BY species"; $sql = "SELECT DISTINCT region FROM alerts WHERE Date BETWEEN '".$thestartdate ."' AND '".$theenddate ."' AND species = '".$species_filter ."' GROUP BY region"; } else { // The species is Not Set echo "Species is NOT set - "; list($arr1, $arr2) = datedropdown_funct($date_filter); $date_filter_options= $arr1; $thestartdate.= $arr2; $sql2 = "SELECT * FROM alerts WHERE Date BETWEEN '".$thestartdate ."' AND '".$theenddate ."' AND region = '".$region_filter ."' ORDER BY Date DESC, time DESC "; $sql3 = "SELECT DISTINCT species FROM alerts WHERE Date BETWEEN '".$thestartdate ."' AND '".$theenddate ."' AND region = '". $region_filter . "' GROUP BY species"; $sql = "SELECT DISTINCT region FROM alerts WHERE Date BETWEEN '".$thestartdate ."' AND '".$theenddate ."' GROUP BY region"; } } else { // The region is not set echo "Region is NOT set - "; // Check to see if species is set if(isset($species_filter) and strlen($species_filter) > 0) { // The species is set echo "Species is Set :- " . $species_filter . " - "; list($arr1, $arr2) = datedropdown_funct($date_filter); $date_filter_options= $arr1; $thestartdate.= $arr2; $sql2 = "SELECT * FROM alerts WHERE Date BETWEEN '".$thestartdate ."' AND '".$theenddate ."' AND species = '".$species_filter ."' ORDER BY Date DESC, time DESC "; $sql3 = "SELECT DISTINCT species FROM alerts WHERE Date BETWEEN '".$thestartdate ."' AND '".$theenddate ."' GROUP BY species"; $sql = "SELECT DISTINCT region FROM alerts WHERE Date BETWEEN '".$thestartdate ."' AND '".$theenddate ."' AND species = '".$species_filter ."' GROUP BY region"; } else { // The species is NOT Set echo "Species is NOT set - "; list($arr1, $arr2) = datedropdown_funct($date_filter); $date_filter_options= $arr1; $thestartdate.= $arr2; $sql2 = "SELECT * FROM alerts WHERE Date BETWEEN '".$thestartdate ."' AND '".$theenddate ."' ORDER BY Date DESC, time DESC "; $sql3 = "SELECT DISTINCT species FROM alerts WHERE Date BETWEEN '".$thestartdate ."' AND '".$theenddate ."' GROUP BY species"; $sql = "SELECT DISTINCT region FROM alerts WHERE Date BETWEEN '".$thestartdate ."' AND '".$theenddate ."' GROUP BY region"; } } } else { // The date is not set $date_filter_options = '<option value="">Select</option><option value="Today">Today</option><option value="Last 48hrs">Last 48hrs</option><option value="Last week">Last Week</option><option value="last month">Last Month</option>'; echo "Date is NOT set - "; // Check to see if Region is set if(isset($region_filter) and strlen($region_filter) > 0) { // The region is set echo "Region is Set :- " . $region_filter . " - "; // Check to see if species is set if(isset($species_filter) and strlen($species_filter) > 0) { // The species is Set echo "Species is Set :- " . $species_filter . " - "; } else { // The species is not set echo "Species is NOT set - "; } } else { // The region is Set echo "Region is NOT set - "; // Check to see if species is set if(isset($species_filter) and strlen($species_filter) > 0) { // The species is Set echo "Species is Set :- " . $species_filter . " - " ; // Build the SQL strings $sql2 = "SELECT * FROM alerts WHERE species ='".$species_filter ."' ORDER BY Date DESC, time DESC "; $sql = "SELECT DISTINCT region FROM alerts GROUP BY region"; $sql3 = "SELECT DISTINCT species FROM alerts WHERE species ='".$species_filter ."' GROUP BY species"; // } else { // The species is not set echo "Species is NOT set - "; // We will only display 5 days worth of Data $year =date("Y"); $month = date("m"); $day = date("d")-5; $thestartdate = $year . '-' .$month . '-' . $day ; // Build the SQL strings $sql2 = "SELECT * FROM alerts WHERE Date BETWEEN '".$thestartdate ."' AND '".$theenddate ."' ORDER BY Date DESC, time DESC "; $sql3 = "SELECT DISTINCT species FROM alerts GROUP BY species"; $sql = "SELECT DISTINCT region FROM alerts GROUP BY region"; } } } $result2 = $db->sql_query($sql2); if (!($result2 = $db->sql_query($sql2))) { die("Database Query Failed" . mysql_error()); } $i = 1; while ( $row2 = $db->sql_fetchrow($result2) ) { $template->assign_block_vars('alerts', array( 'POS' => $i , 'REGION' => str_replace("&", " & ", $row2['region']), 'SPECIES' => str_replace("%", "'",$row2['species']), 'DATE' => $row2['Date'], 'TIME' => $row2['time'], 'COMMENTS' => str_replace("'", "%",$row2['comments']), ) ); $i++; } $template->assign_vars(array( 'USERNAME' => htmlspecialchars($userdata[username]), 'REGION_FILTER' => str_replace("&", " & ", $region_filter_options), 'SPECIES_FILTER' => $species_filter_options, ) ); $result = $db->sql_query($sql); if (!($result = $db->sql_query($sql))) { die("Database Query Failed" . mysql_error()); } // This is where you would add a new VARS Array if you intend to use your own custom VARS. while ($row = $db->sql_fetchrow($result)) { $selected = (isset($_GET['REGION_FILTER']) AND $_GET['REGION_FILTER']==$row['region']) ? ' selected="selected"' : '' ; $region_filter_options .= "<option value=\"{$row['region']}{$selected}>{$row['region']}</option>\n"; } $result = $db->sql_query($sql3); if (!($result = $db->sql_query($sql3))) { die("Database Query Failed" . mysql_error()); } // This is where you would add a new VARS Array if you intend to use your own custom VARS. while ($row = $db->sql_fetchrow($result)) { $selected = (isset($_GET['SPECIES_FILTER']) AND $_GET['SPECIES_FILTER']==$row['species']) ? ' selected="selected"' : '' ; $species_filter_options .= "<option value=\"{$row['species']}{$selected}>{$row['species']}</option>\n"; } $template->assign_vars(array( 'USERNAME' => htmlspecialchars($userdata[username]), 'REGION_FILTER' => str_replace("&", " & ", $region_filter_options), 'SPECIES_FILTER' => $species_filter_options, ) ); $template->assign_vars(array( 'USERNAME' => htmlspecialchars($userdata[username]), 'DATE_FILTER' => $date_filter_options, ) ); // Build the page $template->pparse('body'); // standard page footer include(IP_ROOT_PATH . 'includes/page_tail.'.PHP_EXT); } ?> regards
  4. I have read that artcle somewhere and that is why i wrote this if(isset($_GET["REGION_FILTER"]) AND $_GET["REGION_FILTER"] = $row['region'] AND strlen($_GET["REGION_FILTER"]) > 0) //if($region_filter = $row['region'] AND strlen($region_filter) > 0) { $region_filter_options .= '<option value="' . $row['region'] . '" SELECTED>' . $row['region'] . '</option>'; } else { $region_filter_options .= '<option value="' . $row['region']. '">' . $row['region'] . '</option>'; } if i am correct this translates to if(isset($_GET["REGION_FILTER"]) AND $_GET["REGION_FILTER"] = $row['region'] AND strlen($_GET["REGION_FILTER"]) > 0) if REGION_FILTER is set and REGION_FILTER = field.Region and the Length of REGION_FILTER >0 then $region_filter_options .= '<option value="' . $row['region'] . '" SELECTED>' . $row['region'] . '</option>'; let region_filter_options = <option value= " field.Region " SELECTED> field.Region </option>'; this should only be done once a match of value selected is found in field.region. else this gets done $region_filter_options .= '<option value="' . $row['region']. '">' . $row['region'] . '</option>'; ( Which is non SELECTED ) for all other field.region values Does that make sense or have i got this completely wrong
  5. This is the code on the HTML page <form action="alertz_VIP.php" method="GET"> <select name=REGION_FILTER size="1" id=REGION_FILTER onchange="this.form.submit()"> <option value="">Select </option> <option value={REGION_FILTER}></option> </select> As you can see changing the dropdown option results in the page being submitted. The Alertz_VIP.php page populates the {REGION_FILTER} Field if that makes sense
  6. Evening People I have this drop downbox on a HTML page, it is populated from a PHP page, if the user makes a selection i want that selection to be retained once the page refreshed. What i have is while ($row = $db->sql_fetchrow($result)) { if(isset($_GET["REGION_FILTER"]) AND $_GET["REGION_FILTER"] = $row['region'] AND strlen($_GET["REGION_FILTER"]) > 0) //if($region_filter = $row['region'] AND strlen($region_filter) > 0) { $region_filter_options .= '<option value="' . $row['region'] . '" SELECTED>' . $row['region'] . '</option>'; } else { $region_filter_options .= '<option value="' . $row['region']. '">' . $row['region'] . '</option>'; } } REGION_FILTER is the ID of the option box The drop down box is populated from the database but i cant seem to get the selected bit working. Can someone help identify what i have done wrong ? regards
  7. Hi Guys I have created a function, well i think i have function datedropdown_funct() { switch ($date_filter) { case "Today": $retval = '<option value="">Select</option><option value="Today" SELECTED>Today</option><option value="Last 48hrs">Last 48hrs</option><option value="Last week">Last Week</option><option value="last month">Last Month</option>'; break; case "Last 48hrs": $day = date("d")-1; $retval = '<option value="">Select</option><option value="Today">Today</option><option value="Last 48hrs" SELECTED>Last 48hrs</option><option value="Last week">Last Week</option><option value="last month">Last Month</option>'; break; case "Last week": $day = date("d")-7; $retval = '<option value="">Select</option><option value="Today">Today</option><option value="Last 48hrs">Last 48hrs</option><option value="Last week" SELECTED>Last Week</option><option value="last month">Last Month</option>'; break; case "last month": $month = date("m")-1; $retval = '<option value="">Select</option><option value="Today">Today</option><option value="Last 48hrs">Last 48hrs</option><option value="Last week">Last Week</option><option value="last month" SELECTED>Last Month</option>'; break; case "last 3 months": $month = date("m")-3; $retval = '<option value="">Select</option><option value="Today">Today</option><option value="Last 48hrs">Last 48hrs</option><option value="Last week">Last Week</option><option value="last month">Last Month</option><option value="last 3 months" SELECTED>Last 3 Month</option>'; break; default: // Default is the last 48hrs $day = date("d")-1; } return $retval; } it gets called like so $date_filter_options= datedropdown_funct(); The variable $date_filter_options should take on the $retval value, but it doesnt appear to be calling the function Any ideas or correction where i have screwed up ? regards
  8. One last question i have for the night is:- You mentioned creating a function, where do i put the function has the function to be before the call or after the call in the code layout ? I know i can put it in a seperate file, but i dont want to do that until i am comfortable that it all works if you know what i mean. Cheers
  9. Cheers for that Anti-Moronic I had prior to you showing reduced code have done that, i have used if statements to check for dropdown settings. I will repost what i have when i am finished, i know it can be streamlined further and would appreciate any feedback. As i say i am learning and learning fast. Dont want to be a PHP master jedi, just wanna be able to manage my own website if that make sense, but i am enjoying it all the same. Cheers
  10. Make more of an effort to resolve first -- Been at it for 3 days now, my code has changed drastically from the one i have put up, but still no joy. How much longer do i need to look / try to resolve before i get help. As i said i am new to PHP. Would appreciate it if you did look at it, basically i have a page that has 3 drop down boxes, I am trying to do 2 things 1) when an option in any of the drop down boxes is selected, the page refreshes and the selection is maintained. 2) No matter which drop down you select from the php code will perform an database query and populate the other 2 drop down boxes and also updates the screen based upon selected criteria. If you then pick a second option from one of the other drop down box, the database selection is filtered further. I know its a big project for a newbie to try and pull off. Appreciate any support i can get. Regards
  11. I appreciate that JCBones, i didnt know that. so basically if i use ' instead of " then i can have text or variables in it, variables are automatically coverted to text ? Thanks
  12. Sorry, I did say i was a noob at PHP, i Just didnt think that would work , i thought it woul look at it as being text instead of a string the way he had it. regards
  13. Hi There I think the line $result = mysql_query("SELECT* FROM student WHERE $field = '$searchword'") or trigger_error('MySQL error: ' . mysql_error()); should read $result = mysql_query("SELECT* FROM student WHERE $field = '" . $searchword . "'") or trigger_error('MySQL error: ' . mysql_error()); Notice the change - '" . $searchword . "'", you need to break out of the string and add a string if that makes sense, what you have is you are telling it to pull from database where field = "$searchword" and not field =$searchword Hope that makes sense as i am a noob myself, i would get this confirmed but im almost certain thats where your problem lies. Hope it helps Regards
×
×
  • 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.