PHP - User Generated Tables (ala Filemaker), Sorting/filtering/pagination
I’m writing a small application that allows me/users to add their own inputs so they can store their own data. It’s kind of like, a user defined database. Think of a super simple “filemaker” kind of application. The way I’ve set this up is like this:
Table: item fields: item_id, user_id Table item_attribute Fields: item_attribute_id, item_id, name, valueAfter my query I end up with stuff like this: $data = array( 0=>array( '123'=>array( 'name'=>'Year', 'value'=>'1985' ), '7'=>array( 'name'=>'Title', 'value'=>'Title For 1985' ), '25'=>array( 'name'=>'Length', 'value'=>'60' ) ), 1=>array( '123'=>array( 'name'=>'Year', 'value'=>'1990' ), '7'=>array( 'name'=>'Title', 'value'=>'Title For 1990' ), '25'=>array( 'name'=>'Length', 'value'=>'44' ) ), 2=>array( '123'=>array( 'name'=>'Year', 'value'=>'1965' ), '7'=>array( 'name'=>'Title', 'value'=>'Title For 1965' ), '25'=>array( 'name'=>'Length', 'value'=>'122' ) ) );This seems to work great as there is no limit to what a user can add - it's working like I would like it to... But now that I’m trying to add sorting/filtering/pagination to results things have gotten extremely difficult on the back end. The only thing I can think of is to pull all the data and then use php algorithms to sort/filter/paginate before sending over to web page. I can see this getting slow if I eventually have to pull 1000s of records. Does anyone have advice in these matters? Should I rethink my db design? Can the results be used to create a temporary table and then sort on it? (don'n know how or if this is even possible) I need some help Thanks. Edited by fivestringsurf, 16 November 2014 - 12:28 PM. Similar TutorialsHello Everybody! From all the PHP forums, this seems to be the best one, since I find the words 'freaks' and 'addicted' everywhere, so I give it a shot for the first time Yesterday I've been struggling with a piece of code all day, which got me really frustrated. I'm a bit of a noob yet, but usually Iget quite far with a bit of googling. Not this time... I have a code and I want to be able to sort and filter the code with a form (It's for a portfolio). I know it has a lot to do with XXXX, but I can't get it working. Do I have to use a double array instead? (tried that also, but then I have to find a way to get the paging back...) Can someone help me out a bit maybe? I would be very very graceful! Here is the code I'm using: The index.php Code: [Select] <?php $page_comments = 2; //number of comments per page /* DEZE HIERONDER KAN MISSCHIEN WEG?? */ $page = 0; $page = (int)$_GET['p']; ?> <!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> <title>Sort/filter form</title> <style type="text/css"> <!-- div.gbsign{color:#F00;} .gbname{font-weight:bold;color:#FC0;} .gbdate{margin-left:30px;color:#F0C;} p.gbmessage{margin-top:-12px;color:#FCC;} p.extra_p{margin-top:-12px;color:#0F0;} p.extra2_p{margin-top:-12px;color:#00F;} --> </style> </head> <body> <form method=get style="display: inline;" name=''> <select name=orderby onChange=""> <option value='relevance'>Relevance</option> <option value='year'>Year</option> <option value='title_asc'>Title (A - Z)</option> <option value='title_desc'>Title (Z - A)</option><BR /> </select> <input type="checkbox">Film</input> <input type="checkbox">TV</input> <input type="checkbox">Fiction</input> <input type="checkbox">Documentary / Reality</input> <input type="checkbox">Commercial</input> <input type="checkbox">In Opdracht</input> </form> <?php $gbfile = 'gbcontentfile.php'; $fh = @fopen($gbfile, "r"); $fcontent = @fread($fh, filesize($gbfile)); if($fcontent){ $cnt = substr_count($fcontent,'<?php /* '); $cnt = $cnt/2; $maxp = 0; if($cnt>$page_comments)$maxp = (int)($cnt/$page_comments); preg_match_all("/\<\?php .*? \?\>(.*?)\<\?php .*? \?\>/is", $fcontent, $entries); $ini = $page*$page_comments; $end = ($page+1)*$page_comments; $ovo = array('<1>','<2>','<3>','<4>','<5>','<6>','<7>'); $sovim = array( "<div class=\"gbsign\"> <p><span class=\"gbname\">", "</span> <span class=\"gbdate\">", "</span> </p> <p class=\"gbmessage\">", "</p> <p class=\"extra_p\">", "</p> <p class=\"extra2_p\">", "</p> <p class=\"extra2_p\">", "</p> <p class=\"extra2_p\">", " </p> </div> " ); for($j=$ini;$j<$end;$j++)echo str_replace($ovo,$sovim,$entries[1][$j]); if($maxp>-1){ echo '<p>'.strstr($fcontent,'<!--').' Pagina '; $gap = ""; for($j=0;$j<$maxp+1;$j++){ if($j==0||$j==$maxp||($j-$page)*($j-$page)<26){ echo $gap; $gap = ""; if($j!=$page)echo "- <a href=\"?p=".$j.$si."\">".($j+1)."</a> " ; /* HIER KOMT NORMAALGESPROKEN (VOOR HET VRAAGTEKEN) DE BESTANDSNAAM VAN DIT DOCUMENT (nu niet ivm index) */ else echo "- <b>".($j+1)."</b> " ; } else $gap = "<b>.....</b>"; } echo '</p>'; } } ?> </body> </html> This is the 'database' gbcontentfile.php with the info: Code: [Select] <?php /* ARTICLE START */ ?><1>TV<2>Fiction<3>ATitle1<4>1<5>Small Example text<6>THE text<7>extra option<?php /* ARTICLE END */ ?> <?php /* ARTICLE START */ ?><1>Film<2>Fiction<3>BTitle2<4>3<5>Small Example text<6>THE text<7>extra option<?php /* ARTICLE END */ ?> <?php /* ARTICLE START */ ?><1>TV<2>Reality<3>CTitle3<4>2<5>Small Example text<6>THE text<7>extra option<?php /* ARTICLE END */ ?> I hope that someone can help me out. I found this already, but I can not get the two combined: Code: [Select] <?PHP $data = array( array("firstname" => "Mary", "lastname" => "Johnson", "age" => 25), array("firstname" => "Amanda", "lastname" => "Miller", "age" => 18), array("firstname" => "James", "lastname" => "Brown", "age" => 31), array("firstname" => "Patricia", "lastname" => "Williams", "age" => 7), array("firstname" => "Michael", "lastname" => "Davis", "age" => 43), array("firstname" => "Sarah", "lastname" => "Miller", "age" => 24), array("firstname" => "Patrick", "lastname" => "Miller", "age" => 27) ); ?> <?PHP function orderBy($data, $field) { $code = "return strnatcmp(\$a['$field'], \$b['$field']);"; usort($data, create_function('$a,$b', $code)); return $data; } $data = orderBy($data, 'age'); ?> Thanks in advance!! Sander when i filter a search it shows 1st page but cannot show contents on 2nd page. i have the following code: <? include_once "connect.php"; if(trim($_REQUEST['searchkeyword'])!="") { $searchkeyword=$_REQUEST['searchkeyword']; $searchkeyword1=str_replace(".", "", $searchkeyword); } if($_REQUEST['stype']!="" && $_REQUEST['start']=="" && trim($_REQUEST['searchkeyword'])!="") { $qry="INSERT INTO search_history set search_type='".$_REQUEST['stype']."', search_text='".$_REQUEST['searchkeyword']."', search_date=now(), result_url='course_listing.php?searchkeyword=".$_REQUEST['searchkeyword']."'"; mysql_query($qry); $_GET['stype']=""; } $PVR_SectionID="2"; $extQry=""; $extQry2=""; if(isset($_REQUEST['searchkeyword'])) { $extQry.=" and (department like '%".$_REQUEST['searchkeyword']."%' or course_title like '%".$searchkeyword1."%' or course_title like '%".$_REQUEST['searchkeyword']."%' or course_desc like '%".$_REQUEST['searchkeyword']."%')"; $extQry2=" and (name like '%".$_REQUEST['searchkeyword']."%' or contact_name like '%".$_REQUEST['searchkeyword']."%' or country like '%".$_REQUEST['searchkeyword']."%' or city like '%".$_REQUEST['searchkeyword']."%' or description like '%".$_REQUEST['searchkeyword']."%')"; } if(isset($_REQUEST['subject'])) { $extQry.=" and sub_id in ("; $cnt=0; foreach($_REQUEST['subject'] as $k=>$v) { $cnt++; if($cnt>1) { $extQry.=",".$v; } else { $extQry.=$v; } } $extQry.=") "; } if(isset($_REQUEST['region'])) { $extQry.=" and uni_id in (SELECT id from institution where is_active='1' and reg_id in("; $extQry2.=" and reg_id in("; $cnt=0; foreach($_REQUEST['region'] as $k=>$v) { $cnt++; if($cnt>1) { $extQry.=",".$v; $extQry2.=",".$v; } else { $extQry.=$v; $extQry2.=$v; } } $extQry.=") ) "; $extQry2.=")"; } if(isset($_REQUEST['studymode'])) { $extQry.=" and id in ( SELECT course_id from course_qdm where mode in ("; $cnt=0; foreach($_REQUEST['studymode'] as $k=>$v) { $cnt++; if($cnt>1) { $extQry.=",'".$v."'"; } else { $extQry.="'".$v."'"; } } $extQry.=") ) "; } if(isset($_REQUEST['institution'])) { $extQry.=" and uni_id='".$_REQUEST['institution']."'"; } $courseQry="SELECT * FROM course where is_active='1' $extQry "; $crsRes=mysql_query($courseQry); $totCourse=mysql_affected_rows(); $pgLimit=10; $shFrom=intval($_REQUEST['start'])+1; $shTo= $shFrom + $pgLimit - 1; if($shTo>$totCourse) $shTo=$totCourse; $CRSresult=$prs_pageing->number_pageing22($courseQry,$pgLimit,10,'N','Y'); $courseQry="SELECT * FROM institution where is_active='1' $extQry2"; $instRes=mysql_query($courseQry); $totInstitution=mysql_affected_rows(); ?> <!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=utf-8" /> <? getMeta("4") ;?> <?php include("head_script.php"); ?> <script src="../../../../DOCUME~1/Farhan/LOCALS~1/Temp/Scripts/cforms.js" type="text/javascript"></script> <script src="../../../../DOCUME~1/Farhan/LOCALS~1/Temp/SpryAssets/SpryAccordion.js" type="text/javascript"></script> <script type="text/javascript"> <!-- function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } //--> </script> <link href="../../../../DOCUME~1/Farhan/LOCALS~1/Temp/SpryAssets/SpryAccordion.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="950" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><? include_once "header.php"; ?></td> </tr> <tr> <td><table width="950" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="753" height="32"><div id="track_2"><a href="../../../../DOCUME~1/Farhan/LOCALS~1/Temp/index.php" style="padding-left:0px;"><img src="../../../../DOCUME~1/Farhan/LOCALS~1/Temp/images/btn_home.gif" /></a><a href="../../../../DOCUME~1/Farhan/LOCALS~1/Temp/course_search.php">Find courses and research</a><span>Search Results</span></div></td> <td width="10" rowspan="2"> </td> <td width="187" rowspan="2" align="center" valign="top" bgcolor="#f9f9f9"><? include_once "banners_block.php"; ?></td> </tr> <tr> <td valign="top" id="contents"> <h1>you have <?=$totCourse;?> Course Search Result</h1> <? include "course_filter.php"; ?> <? if($CRSresult[1]!="") { ?> <div> <h2>Showing <?=$shFrom;?>-<?=$shTo;?></h2></div> <? while($CRSrow=mysql_fetch_array($CRSresult[0])) { ?> <div class="mix"> <a href="<?=course_details_URL($CRSrow['id']);?>"><b><?=stripslashes($CRSrow['course_title']);?></b></a> <? $quaRes=mysql_query("SELECT qualification from course_qdm where course_id='".$CRSrow['id']."'"); if(mysql_affected_rows()>0) { $cnt=0; $qArr=array(); while($quaRow=mysql_fetch_array($quaRes)) { if(!array_key_exists($quaRow['qualification'],$qArr)) { $cnt++; if($cnt>1) { echo " / ".stripslashes($quaRow['qualification']); } else { echo stripslashes($quaRow['qualification']); } $qArr[$quaRow['qualification']]=1; } } } ?> <a href="<?=university_prof_details_URL($CRSrow['uni_id']);?>" ><strong><?=stripslashes(GetValue("institution","name","id",$CRSrow['uni_id']));?></strong></a> - <?=stripslashes($CRSrow['department']);?> <br /> <span><?=substr(strip_tags(stripslashes($CRSrow['course_desc'])),0,100);?>...</span> <a href="<?=course_details_URL($CRSrow['id']);?>"><strong>read more</strong></a> </div> <? } ?> <?php $sub_get = $_GET['subject']; $s_pass = $sub_get[0]; ?> <?php /*?><div class="link_large"><a href="all_course.php?q=<?=base64_encode($extQry);?>">More Courses</a></div><?php */?> <? } ?> <div> <?=$CRSresult[1];?> </div> </td> </tr> </table></td> </tr> <tr> <td><? include_once "bookmark.php"; ?></td> </tr> <tr> <td><? include_once "footer.php"; ?></td> </tr> </table> </body> </html> i have an issue in plain php when i filter my search result for specific search it shows 1st page but can not give results on 2nd page i am sending both the files includes: course_listing.php course_filter.php Hi all, I am currently returning candidates from a database initially just by the highest candidate id to the lowest... i.e. newest candidates to oldest. I have introduced a sort feature which works just fine, the problem is I am displaying my results over a few pages using pagination. The problem arises once I sort my results and then try to click onto the next page of results. Basically it is just resetting the sort as the sort relies on a button being pressed, which obviously isn't happening when the user is trying to get the next page of results. I'm not sure exactly which section of code would be relevant to this so I have posted the whole script... additionally if you need to take a look at it in action you can do so he http://www.beta.teachingagencies.co.uk/search_jobseekers.php As I say I know the problem is that when the page is changed the value is lost, but I don't have a clue how to solve the problem! Any help or advice would be appreciated. Many thanks, Greens85 I'm not sure of the appropriate subject line for this feature, but hopefully I'm close. I'll try to describe what I'm trying to do. The most common place you see this is on web based file uploads so I'll use it as my example. Let's say I want to allow my user to upload files so there is a text box where they enter the file name. The user is allowed to upload as many files as he wants with 1 push of the submit button. Upon the loading of the form, there will be 5 textboxes for file upload, but if the user wants to upload more than 5 files, there is a link that is clicked and I think via ajax or javascript another textbox will be added. The user can do this for as many files he wants to upload. This is what it looks like to the user, but then when the form is submitted how are these variables referenced? So how is this setup in the main form and how are the variables referenced after form submission? If anyone can point me to a good web tutorial on this type of thing I would appreciate it. Thanks Carl Hi. I have a rating site where users fill in a name of what they are rating, comments about it and a rating and submit it to my database. I then have another page which shows all of these entries but only the name and overall rating using php. What I want is for users to click on the name and it take them to a separate page which displays all the comments and ratings for that item. As users can add items to rate I cant set up a page for each manually so was wondering how to do it dynamically. Everything i throw into google leads me in the wrong direction though. If someone could point me to a good tutorial or give me an idea about what to search id be very grateful. Cheers. Hello 1) I am reading two good tutorials for building a search page with pagination: http://www.phpfreaks.com/tutorial/basic-pagination http://php.about.com/od/phpwithmysql/ss/php_pagination.htm Before I ask the big question, I would like to know how does a query look like when searching multiple tables (e.g three) in the same time. Table1/Table2/Table3. May you kindly give me example? 2) The problem is that I have multiple tables with the same structure to search e.g. (title, body) a) how I will know the ROWS NUMBER returned by the search query? it doesn't look a smart way to query each table and them count the results, and this basically takes much time right? b) when displaying the result, how I will be able to set the correct hyperlink for each result? you know, each table is a different subject, each one is located in different folder. Thank you SO MUCH I have a form and script that is used to collect information from users. There is one field that is url. There is one field that is email. I want to filter out scripts. I also only want to allow url in the url field and email in the email field. Is there an easy way to filter? I have tried several pieces of code to no avail. Code: [Select] <?php $root = $_SERVER['DOCUMENT_ROOT']; include('/home/arts/public_html/shows/includes/config.db.php'); if ($link) { foreach ($_POST as $k => $v) { if (($k == "start_date") || ($k == "end_date") || ($k == "application_dead")) { $varray = explode("/",$v); $v = $varray[2] . "-" . $varray[0] . "-" . $varray[1]; } $v = "'" . addslashes($v) . "'"; if($k != "captcha_code") { $keys[] = $k; $vals[] = $v; } } $fields = implode(",", $keys); $values = implode(",", $vals); //$fields = "id," . $fields; //$values = "null," . $values; $sql = "INSERT into craft_shows ($fields) VALUES ($values)"; $result = mysql_query($sql,$link); if (!$result) { die('There was a problem with your submission. Refresh the page to try again'); } else { echo "Thank you for your submission.<br>"; echo "<a href=\"http://www.artsandcraftsnetwork.com/shows/\">Back to shows</a><br>"; echo "<a href=\"http://www.artsandcraftsnetwork.com/shows/shows_submit.php\">Submit another show</a>"; } } ?> I'm pretty sure the problem is starring me in the face, but I can't seem to locate it. function filter($string) { //swear words pulled from bannedwordlist.com $f = fopen('../badwords.txt', 'r'); $bad_words = fread($f, filesize('../badwords.txt')); $bad_words = explode('\n', $bad_words); $input = strtolower($string); foreach($bad_words as $value) { $string = str_replace($value, '****', $input); } return $string; } UPDATED CODE function filter($string) { //swear words pulled from bannedwordlist.com $f = fopen('../badwords.txt', 'r'); $bad_words = fread($f, filesize('../badwords.txt')); $bad_words = explode('\n', $bad_words); $input = strtolower($string); $string = str_replace($bad_words, '****', $input); return $string; } I've already echoed out $value in the foreeach loop, and it does correctly retrieve the bad words and put them into an array. My only problem is, the returned string is still in strtolower() form, and the words aren't censored. :/ Hi all, I was wondering if i can filter certain log files like using 2 keywords and get all the info inbetween? The log files are like <1 MB. The other problem i encounter is howto since i looked all over the net but cant seem to find usefull info about it. Can you help me out here? Hi there I have the following array . Code: [Select] $products = array( array( Code => "CF1", Items => "Sand Tray", Cat => 'Tray', ), array( Code => "CF2", Items => "Mobile Computer Table", Cat => 'Table', ), array( Code => "CF3", Items => "General Service Trolley", Cat => 'Trolley', ), array( Code => "CF4", Items => "TV Trolley", Cat => 'Trolley', ), array( Code => "CF5", Items => "Overhead Projector Trolley", Cat => 'Trolley', ), array( Code => "CF6", Items => "Book Trolley", Cat => 'Tolley', ), array( Code => "CF7", Items => "Stacking Chairs", Cat => 'Chairs', ), ); What I want to do is select each by 'Cat'. For example I simply want to display all the trolleys. I was wondering how I do this? What functions would I use in PHP? Thanks a million I want to create a feature as you see nn this image, where it says 'filter your results' if a user clicks 'Detached Houses' then only detached houses will be displayed. if a user clicks 'Semi-detached' then only semi detached houses will be shown. Any help is really appreciated, thank you. Code: [Select] <table border="0" cellpadding="0" cellspacing="0"> <tr> <td><div id="filter"><p class="houses" style="font-family:helvetica;color:#0155a1;font-size:14px;background:url(cutouts/forsale/filter.jpg) no-repeat;"><b><u>Houses</u></b> <br /> <span class="dh"><b><u>Detached Houses</u></b></span><?php // Make a MySQL Connection mysql_connect("localhost", "admin", "1admin") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); // Get a specific result from the "example" table $result = mysql_query("SELECT * FROM example WHERE name='Sandy Smith'") or die(mysql_error()); // get the first (and hopefully only) entry from the result $row = mysql_fetch_array( $result ); // Print out the contents of each row into a table echo $row['name']." - ".$row['age']; ?> <br /> <span class="dh"><b><u>Semi-detached houses</u></b></span> <br /> <span class="dh"><b><u>Terraced houses</u></b></span> <br /> <br /> <b><u>Flats / Apartments</u></b> </p></div></td> Hi guys I was wondering if anyone could point me in the right direction with this. I am using JSON to return the contents of a directory and then using a foreach loop to print each one to a new row in a table. Is there anyway to filter the results? Basically I just want to show the files that end in a .jar extension? Currently all sub directories and files are shown, however all the files I need to pull will be in the main directory. This is what I am using: Code: [Select] <?php foreach ($installedplugins1['success'] as $v) { echo "<tr><td>".$v."</td>"; echo "<td><a href='index.php?dp=".$v."'>Disable Plugin</a></td>"; } ?> Any hints or reading material? Cheers hey guys i was generally wondering...is it good practice to add_slashes and use mysqli_real_escape_string when entering data into the database?
then to strip slashes when extracting rows?
is this the right way to go around things...thanks
Hi, I have an issue, I cant filter my data from DB. Whats wrong in my code? <?php /* Include Files *********************/ //include("banners/database.php"); mysql_connect("host", "user", "pwd") or die("Connection Failed"); mysql_select_db("DB")or die("Connection Failed"); ?> <?php $memberIndustries =['memberIndustries']; if (isset($_POST["memberIndustries"])) { $memberIndustries = mysql_real_escape_string ($_POST["memberIndustries"]); $sql="SELECT * FROM Members WHERE Industries_Industry_ID='$memberIndustries'"; $result = mysql_query($sql) or die (mysql_error()); while ($myrowe = mysql_fetch_array($result)) {?> <? // if new member, label it //$todays_date = date("Y-m-d"); //$dateCompare = $myrowe[Creation_Date]+30; //$dateCompare = strtotime(date("Y-m-d", strtotime($myrowe[Creation_Date])) . " +30 days"); //if(strtotime($todays_date)<=$dateCompare){ ?> <table width="100%"> <tr> <td align="right"> <img src="/members/new.gif"> </td> </tr> </table> <? //}?> <? if($myrowe[LOGO_lnk]!='') {?> <img src="<? echo $myrowe[LOGO_lnk]; ?>"> <? } ?> <br /> <br /> <font style="font-family: Arial; font-size: 10.5pt; font-weight:bold;color:#C1121F"> <? echo $myrowe[Company_Title];?> </font> <? if($myrowe[Person_Name_1]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; font-weight:bold;color:#000000"><? echo $myrowe[Person_Name_1];?></font> <font style="font-family: Arial; font-size: 8.5pt; font-weight:bold;color:#000000"><? echo $myrowe[Person_Title_1];?></font> <? } if($myrowe[Person_Name_2]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; font-weight:bold;color:#000000"><? echo $myrowe[Person_Name_2];?></font> <font style="font-family: Arial; font-size: 8.5pt; font-weight:bold;color:#000000"><? echo $myrowe[Person_Title_2];?></font> <? } if($myrowe[Person_Name_2]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; font-weight:bold;color:#000000"><? echo $myrowe[Person_Name_3];?></font> <font style="font-family: Arial; font-size: 8.5pt; font-weight:bold;color:#000000"><? echo $myrowe[Person_Title_3];?></font> <? } if($myrowe[Address_row1]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myrowe[Address_row1];?></font> <? } if($myrowe[Address_row_2]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myrowe[Address_row_2];?></font> <? } if($myrowe[Address_row_3]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myrowe[Address_row_3];?></font> <? } if($myrowe[Phone]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000">Tel:<? echo $myrowe[Phone];?></font> <? } if($myrowe[Fax]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000">Fax:<? echo $myrowe[Fax];?></font> <? } if($myrowe[email]!='') {?> <br /> <a href="mailto:<? echo $myrowe[email];?>"> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myrowe[email];?></font> </a> <? } if($myrowe[web]!='') {?> <br /> <a href="<? echo $myrowe[web];?>"target="_blank"> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myrowe[web];?></font> </a> <? } if($myrowe[Industries_Industry_ID]!=0) { $queryInd = "SELECT Industry_Title FROM Industries WHERE Industry_ID=$myrowe[Industries_Industry_ID]"; $resultInd = mysql_query($queryInd) or die (mysql_error()); $myroweIND = mysql_fetch_array($resultInd) ?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myroweIND[Industry_Title];?></font> <? } if($myrowe[Description]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myrowe[Description];?></font><p></p> <? } ?> <br /><br /> <? } <? }} ?> hi, i am trying to filter my gps history points. i would like to ignore points if they are too close to the previous position. i can do this like so. $old_lat = $old_long = "0"; foreach($history['data'] as $record) { //calculate distance in meters $distance = distance($record['latitude'], $record['longitude'], $old_lat, $old_long, "V"); if($distance >= 300) { echo 'add(jQuery(this), number += 1, "' . date("d-m-Y @ h:i:s",$record['timestamp']) . '", "map_post.php?n=' . $name . 'u=' . $history['user'] . '", "' . $history['user'] . '", "' . $record['latitude'] . '", "' . $record['longitude'] . '");'; $old_lat = $record['latitude']; $old_long = $record['longitude']; } the problem with the above is that if i arrive home at 6pm on friday and stay outside my house for 24hours, it will show the latest position as at 6pm on fri. i would like it to show the 6pm friday position but with a date 'from and to' time like (28/10/11 18:00 - 29/10/11 18:00) rarther than just (28/10/11 18:00) which looks inacurate. Possible? Hi all, I am working on a tool to pull data remotely and the data is set to xml format. I want to post items that meet a certain criteria only, essentially there are several layers/tags on the data being brought over. The sStatus is the primary item I am looking for, not only that but only if it has or equals to "Waiting". Any thoughts or suggestions greatly appreciated. Below is the basic code I have in place currently and am working on. <code> <?php $soapclient = new SoapClient("https://secure.logmeinrescue.com/api/api.asmx?wsdl"); $sEmail = "dummy@dum.com"; $sPassword = "dum123"; $iNodeID = "123456"; $eNodeRef = "NODE"; $sAuthCode = ""; $loginparams = array ( 'sEmail' => $sEmail, 'sPassword' => $sPassword); $loginResult = $soapclient->login($loginparams); $output = array( 'eOutput' => "XML" ); $outputResponse = $soapclient->setOutput($output); $sessionparams = array( 'iNodeID' => $iNodeID, 'eNodeRef' => $eNodeRef, 'sAuthCode' => $sAuthCode ); //get session(s) $sessionresult = $soapclient->getSession($sessionparams); $session = $sessionresult->aSessions; $sessionnodes = $session->SESSION; $session_status = $sessionnodes[$isessionNodes]->sStatus; print_r($sessionresult); ?> </code> First off, i have made a validation class using array_diff() to check if there are invalid characters submitted by a user. Some extracts: Code: [Select] $this->chr_alpha_lower=array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'); $this->chr_alpha_upper=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); $this->chr_numeric=array('0','1','2','3','4','5','6','7','8','9'); $this->chr_symbol=array(' ','!','@','#','$','%','&','(',')','[',']','.',',',':',';','\'','"','/','=','\\','-','_','?'); ... // lets say only alpha and numeric characters are allowed $allowed_characters=array(); $allowed_characters=array_merge($allowed_characters,$this->chr_alpha_lower,$this->chr_alpha_upper); $allowed_characters=array_merge($allowed_characters,$this->chr_numeric); $input_split=str_split($this->input); $invalid=array_diff($input_split,$allowed_characters); if(empty($invalid)){ return true; } return false; I have two questions. First, for acsii characters is this method 'full proof' or is there a way for someone to get around this validation script? Second, a new site im developing is going to be built with UTF-8 in mind so people can use the site in their own language. How do i validate UTF-8 user input? I know about mb_strings and sanitizing UTF-8 input using this: Code: [Select] preg_match_all('/([\x09\x0a\x0d\x20-\x7e]'. // ASCII characters '|[\xc2-\xdf][\x80-\xbf]'. // 2-byte (except overly longs) '|\xe0[\xa0-\xbf][\x80-\xbf]'. // 3 byte (except overly longs) '|[\xe1-\xec\xee\xef][\x80-\xbf]{2}'. // 3 byte (except overly longs) '|\xed[\x80-\x9f][\x80-\xbf])+/', // 3 byte (except UTF-16 surrogates) $input, $clean_pieces ); $clean_output = join('?', $clean_pieces[0] ); But how do i know what to filter? Example: a field for the user to input first name English: only alpha characters Other language: ????? Help much appreciated. Hello,
Is it possible to allow '@' and '.' while maintaining the rest of this regex?
$email= 'adsfsa@asdf.edu'; $email= preg_replace("/[^A-Za-z0-9]/", " ", $email); echo $email; |