Jump to content

alpine

Members
  • Posts

    759
  • Joined

  • Last visited

Everything posted by alpine

  1. sorry about the title, just couln't find one suitable, here is my problem - in my searchform i want to check for occurances of patterns with dot (.) or commas (,) inbetween letters or numbers where it's no space around them - and include the same pattern to the string only with exchanged comma or dot. Example: 3x2.5 == true 2x1,5 == true You 2, whatever == false (note the space) hello. How are you == false (also a space) Ive managed to get this far: [code] preg_match_all("/([A-Z0-9]+[,][A-Z0-9])/i", $text, $array) // or preg_match_all("/([A-Z0-9]+[.][A-Z0-9])/i", $text, $array) [/code] This however produces array[0] and array[1] with the same values. Target is this: $string = "cable 2x2[color=red],[/color]5 cu"; // where 2x2,5 is true $new_string = "cable 2x2[color=red],[/color]5 cu 2x2[color=red].[/color]5"; $string = "cable 7x1[color=red].[/color]0 cu"; // where 7x1.0 is true $new_string = "cable 7x1[color=red].[/color]0 cu 7x1[color=red],[/color]0"; Any help on this ?
  2. btw - i use onkeypress in different terms to suit browsers, but what is to be preferred ? - onkeypress or onkeyup ??? Javascript is a relative new language to mee so i am in a heavy learning cycle now, getting used to the var instead of $ etc *lol*
  3. Thanks for your thought, i still think i am going to stick with the query on keypress and try and optimize it the best i can as i have near 300.000 rows on products in the db and it seems impossible to find a pattern on most searched items. I think i will try to limit the onkey search to maximum 100 results in standard and make an optional more results button and see if that helps - actually it is working very nice and is actually quite fast too - better and better as i move along and continue fine-tuning it  :)
  4. I have a livesearch in ajax handling queries to a rather big mysql table containing rows of products. What i am experiencing some problems with is that the browser occaitionally freezes (firefox,ie etc - doesn't matter) probably due to problems handling the query results as the customer enters characters in the text field. Now i have set it up so that it's needed at least two chars to actually start searching - but what i think would do things a little easier is to delay each keypress (onkeydown,keypress,keydown) so that the search holds a second or so before sending the http request just to limit the number of queries. I played around with my javascript at first, but the best solution i've come up with so far is to add usleep(500000); on top of the php script handling the db-queries to hold on 0.5 sek before starting. Can anyone point out a better solution than this ???
  5. That is brilliant, thank you so much - after working with it and adjusting it to my needs it is happily suggesting web adresses as we speak [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] I really appreciate your explanation as it also helped me figure out another regex issue i was adjusting on my own. Thanks !
  6. Well, unfortenately i just can't get the hang of regex, so i hope someone can help out. I have a database of companys containing am.o.t. company names, email adresses and url's to their web sites. Its however many many thats not registered with url's - and by taking a glance i notice that several of them do have an email adress matching up with a unique domin also representing their company web sites. What i was thinking was to make a url-suggest feature on those companys missing url's IF the email adress domain looks similar to the company name. example: company: Digger A/S email: blah@digger.no = match example: company: Ultra Star AS email: blah@ultra.no = match example: company: Whatever A/S email: blah@no.whatever.net = match example: company: Digger A/S email: blah@yourfreehost.net = NOT match Any ideas on a reges on this feature ?? And a step-by-step explanaition on it would be great too...
  7. You are relying on register globals to be ON here, and you are querying regardless of POST or not being set. AND you are checking for posted variable "pass" while your password textfield is named "password". Work your way with this one, i've not included a "is logged in"-check though. [code] <? session_start() if(isset($_POST['submitform'])) { if(!empty($_POST['user']) || !empty($_POST['pass'])) { $user = htmlspecialchars($_POST['user']); $pass = htmlspecialchars($_POST['pass']); $db = mysql_connect("localhost","root") or die ("cannot connect to database"); mysql_select_db("mike", $db) or die("could not select database"); $result = mysql_query("SELECT * FROM users WHERE userPassword = PASSWORD('$pass') AND userName = '$user'"); if(mysql_num_rows($result) == "1") { $_SESSION['logged_in_user'] = $user; echo "welcome, " . $user; exit(); } else { echo "No record found in the database"; } } else { echo "Please fill out both username and password field.."; } } echo <<<_HTML <form action = "vtcsignin.php" method = "post"> users: <INPUT type = "text" name = "user"><br> password: <INPUT type = "password" name = "pass"><br> <INPUT type = "submit" name = "submitform"> </form> _HTML; ?> [/code] You should also consider moving away from using PASSWORD in your query as it's not supported in newer mysql versions. Move to md5 or sha1 instead.
  8. [code] $idact = $_GET['idact']; [/code]
  9. You need to echo the results, i've set it up like this for you as its more readable in my oppinion [code] <? if ($_post['checkbox'] == 1) { $action = "databaseresultsthumb.php"; } else { $action = "databaseresults.php"; } ?> <form action = "<?php echo $action; ?>" method="get" name="indexform" id="indexform"> [/code] or yours would look like this [code] <form action = "<?php $field1 = $_post['checkbox']; if ( $field1 == 1 ) { echo "databaseresultsthumb.php"; } else { echo "databaseresults.php"; } ?>" method="get" name="indexform" id="indexform"> [/code]
  10. Well, if you have news in a mysql table, my posted code pretty much does what you need to get news - fetching news from mysql isn't going through a switch statement - it is normally fetched based on the $id. What is your table structure then ?
  11. just rename the form action to the same name as you choose on that file, example getpass.php - nothing is to be splitted up. Remember to correct the table and col names, + ofcourse you will need to include a connection to your mysql db.
  12. okay, i'll help you out on the password bit and you can work with this making your own update info form using the mysql --> UPDATE users set name='$name', company='$company' where id='$id' <-- etc Come back for spesific help on this when you are working on it. Work with this to retrieve password (assume the stored password is stored without encryption): [code] <?php $show_pass_form = 1; if(isset($_POST['change'])) { if(!empty($_POST['cname']) OR !empty($_POST['uname']) OR !empty($_POST['umail'])) { foreach( $_POST as $key => $value ) { ${$key} = htmlspecialchars($value); } // change table info to your own $sql = mysql_query("select password from table_users where email = '$umail' and name = '$uname' and company = '$cname'") or die(mysql_error()); if(mysql_num_rows($sql)<>1) {   print "Sorry, no unique user found with your provided information <br />"; } else { $row = mysql_fetch_array($sql); $pass = $row["password"]; // col name in db storing the password   print "Your password is: $pass <br />"; // or preferred is to email it, remove the line above this printing out the password $send_it = mail($umail,"Your password","Your password is: $pass","From: Secret site <info@site.net>"); if($send_it) {   print "Your password is sendt to $umail"; } else {   print "Password was NOT sendt as the email procedure failed..."; } // now we dont need to show the form again $show_pass_form = 0; } } else {   print "All fields needs to be filled in... <br />"; } } if($show_pass_form == 1) { echo <<<__HTML_END <form action="this.php" method="post"> Company:<br /> <input type="text" name="cname" size="25" value="" /> <br /> Logon Name:<br /> <input type="text" name="uname" size="25" value="" /> <br /> Email:<br /> <input type="text" name="umail" size="25" value="" /> <br /> <br /> <input type="submit" name="forgot" value="Retrieve my password" /> </form> __HTML_END; } ?> [/code]
  13. If it's just the password problem its strictly a mysql version issue.
  14. You're not putting the pattern in an array, only pieces of it - this works however: [code] <?php $names = array( "#Google#is", "#Yahoo#is", "#MSN#is" ); $links = array( "<a href='http://www.google.com/'>Google</a>", "<a href='http://www.yahoo.com/'>Yahoo</a>", "<a href='http://www.msn.com/'>MSN</a>" ); $txt = "bacsk ksaj Google jha djshfu MSN dhfow Yahoo"; $txt = preg_replace( $names, $links, $txt ); echo $txt; ?> [/code]
  15. put the pattern in an array aswell, study the [a href=\"http://no.php.net/manual/en/function.preg-replace.php\" target=\"_blank\"]Manual: [a href=\\\"http://no.php.net/manual/en/function.preg-replace.php\\\" target=\\\"_blank\\\"]http://no.php.net/manual/en/function.preg-replace.php[/a][/a]
  16. im not sure i follow, but in a lack of responce - her is a suggestion on setting variables if they don't exist or is false (0): [code] if(!$var) { $var = "whatever"; } [/code]
  17. You don't tell anything about what your exact problem is (errormsg) First off you need to quote [code] // if($page == home) if($page == "home") [/code] should get u one step further
  18. Just change AND to OR and it should work [code] if ($criteria != '') {     $sql = $sql." AND (jobs.job_title LIKE '%".$criteria."%' OR jobs.reference LIKE '%".$criteria."%' OR jobs.job_description LIKE '%".$criteria."%')"; } [/code]
  19. I think i get your point, study and work on this: [code] <?php // prepare to save a html version of news.php // make sure you have a blank html page to duplicate from $source_html_doc = "../newsletter/archive/blank.html"; $today = date(dmY); $new_blank_html_doc = "../newsletter/archive/news_".$today."html"; copy($source_html_doc, $new_blank_html_doc)or die('Could not copy required file'); // start getting the generated contents of news.php ob_start(); require("news.php"); $body_news = ob_get_contents(); // write a html version of it as archive $html_change = fopen ($new_blank_html_doc, 'w'); fwrite ($html_change, $body_news); fclose ($html_change); // END ob_start ob_end_clean(); // For use in HTML email body $email_html_body = $body_news; ?> [/code]
  20. You will find a solution in the [a href=\"http://www.phpfreaks.com/mysqlmanual/page/manual_Functions.html#Fulltext_Search\" target=\"_blank\"]Mysql Manual : [a href=\\\"http://www.phpfreaks.com/mysqlmanual/page/manual_Functions.html#Fulltext_Search\\\" target=\\\"_blank\\\"]http://www.phpfreaks.com/mysqlmanual/page/...Fulltext_Search[/a][/a]
  21. You are doing a lot of if's with one else try something like this [code] if (empty($_POST['firstname'])) { print("Please go back and fill int he First Name field correctly<br />"); } elseif (empty($_POST['emailaddress'])) { print("Please go back and fill in the Email Address field correctly"); } elseif (empty($_POST['verifyemail'])) { print("Please go back and fill in the Verify Email field correctly<br />"); } elseif (empty($_POST['description'])) { print("Please go back and fill in the Description field correctly<br />"); } elseif ($_POST['emailaddress'] !== $_POST['verifyemail']) { print("Unfortunately the email addresses did not match, please recheck what you put"); } else {   // send } [/code]
  22. Youre looking to update table ?? [code] $id = "1"; // row id or similar $clik = "2"; $update = mysql_query("update mclinkscounter set clik = '$clic' where id = '$id'") or die(mysql_error()); // or add up (+) $update = mysql_query("update mclinkscounter set clik = clik + '$clic' where id = '$id'") or die(mysql_error()); [/code]
  23. don't use the dollar-sign within GET or POST etc. [code] // $name = $_GET['$name']; $name = $_GET['name']; [/code] should fix it
  24. I'm not sure if this is what u are looking for, but here is one example to work with. Ofcourse you have to change the table name and col names and work with what and how you want things to appear to the user If this was NOT what u where looking for, please post you current and relevant code [code] <? $id = $_GET['id']; settype($id,"integer"); if(!empty($_GET['id'])) { $sql = mysql_query("select * from table_news where id = '$id'") or die(mysql_error()); $num = mysql_num_rows($sql); if($num == 1) { $row = mysql_fetch_array($sql); $title = $row["title"]; echo $title; // etc } } if(empty($_GET['id']) OR $num <> 1) { $sql = mysql_query("select * from table_news order by id desc") or die(mysql_error()); while($row = mysql_fetch_array($sql)) {   echo $row["title"];   echo "<br />"; } } ?> [/code]
  25. actually, you are asking if the query itself returns true or not and as long as the query runs ok it will return true in my sence. You can use mysql_num_rows to get the number of results. You also should put quotes within your $_POST Try this [code] if (isset($_POST['submit'])){ $searchresults = mysql_query("SELECT * FROM archive WHERE workerName LIKE '%$_POST['search']%'", $db_connection) or die(mysql_error()); if (mysql_num_rows($searchresults) > 0) { echo "Record Found"; } } [/code]
×
×
  • 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.