jeger003 Posted February 17, 2009 Share Posted February 17, 2009 hello, i have a book site and i want users to be able to search books by isbn........the isbn of the books on my site are stored like this 123-45-678-9-10 i want to be able to remove the '-' so that it would be 12345678910 that way when a user searches for that isbn i can do $ISBN = 123-45-678-9-10 str_replace("-", "", $ISBN); but i cant figure how i can remove the '-' of the isbns that are already in the mysql database here is my code so far $search_isbn = mysql_real_escape_string($_POST['isb']); $rpl_isbn = str_replace("-","", $search_isbn); $query_search_exact_match = mysql_query("SELECT listings.title, listings.id, listings.description, listings.search_text, listings.image, listings.date, listings.price, listings.location_city, listings_extra.name, listings_extra.value, listings_extra.classified_id FROM listings,listings_extra WHERE listings_extra.name = 'ISBN%3A' AND listings_extra.classified_id = nvc_classifieds.id AND listings_extra.value LIKE $rpl_isbn") or die(mysql_error()); not sure why but name for ISBN field is stored ISBN%3A i would appreciate any help thanks Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/ Share on other sites More sharing options...
btherl Posted February 17, 2009 Share Posted February 17, 2009 Why don't you just search the ISBN's in the database as they are? Is there a reason that you want to remove the "-"? Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-763867 Share on other sites More sharing options...
drisate Posted February 17, 2009 Share Posted February 17, 2009 technacly you can load the ressult into an array then take out the - and loop the array ... Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-763871 Share on other sites More sharing options...
jeger003 Posted February 17, 2009 Author Share Posted February 17, 2009 yes, it wont be able to find any isbn.....if a user did 9780135048160 and the isbn is stored as 97-801-350-4816-0 it wont find a match Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-763873 Share on other sites More sharing options...
jeger003 Posted February 17, 2009 Author Share Posted February 17, 2009 technacly you can load the ressult into an array then take out the - and loop the array ... not sure what you mean exactly.....example possible? Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-763876 Share on other sites More sharing options...
drisate Posted February 17, 2009 Share Posted February 17, 2009 You load the table into an array then you replace the - by nothing and you search and loop while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $my_array[] = $row; } But why not run a maintenance script to loop the current data and take out the - right away and modify the insert script to filter them out before they are inserted? Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-763880 Share on other sites More sharing options...
jeger003 Posted February 17, 2009 Author Share Posted February 17, 2009 You load the table into an array then you replace the - by nothing and you search and loop while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $my_array[] = $row; } But why not run a maintenance script to loop the current data and take out the - right away and modify the insert script to filter them out before they are inserted? problem is my site is a purchased script.....i know what you mean but i wouldn't be able to figure out where to make it do that....... but....with the code you provided....i honestly have no clue where and how i can use it.......do you mean that i would first call the ISBN fields and then str_replace the "-" then run it back into a new query and match it with the users input? Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-763900 Share on other sites More sharing options...
drisate Posted February 17, 2009 Share Posted February 17, 2009 well then the only thing i can think of is duplicate the table, run this script $transaction = mysql_query("SELECT * FROM table where name like '%-%'") or die (mysql_error()); while($trans = @mysql_fetch_array($transaction)){ $string = str_replace('-', '' $trans[name]); $update = mysql_query("UPDATE table SET name='$string'") or die (mysql_error()); } Then you make your select, output the query, and delete the new table or keep it synchronized But thats just because i don't see what the code looks like ... the real best way would be to check how your script works and see how they diled with the - issue. Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-763928 Share on other sites More sharing options...
jeger003 Posted February 17, 2009 Author Share Posted February 17, 2009 is there a way to make it displays numbers only and make it ignore all other values or characters? Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-763965 Share on other sites More sharing options...
coolboy0316 Posted February 17, 2009 Share Posted February 17, 2009 i really don't know what you mean? do you want change the data in the database ,or just for user search. Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-763988 Share on other sites More sharing options...
9three Posted February 17, 2009 Share Posted February 17, 2009 $ISBN = "1234-56-789-00"; $body = str_replace("-", "", $ISBN); echo $body; Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-764006 Share on other sites More sharing options...
jeger003 Posted February 17, 2009 Author Share Posted February 17, 2009 yea i wanted to be able to call just 'numbers' in a query. thought maybe there is a way to do that so that it would ignore the '-' in ISBN numbers stored in the db. but i figured out to do it this way....i would appreciate anyone looking at it and hopefully improving in any way.....my other issue is that sometimes users are retarded and they would enter ENTER ISBN: ISBN:(number) and this means i have to string replace ISBN: as well.... here is my code: it works $query_search_exact_match = mysql_query("SELECT listings.title, listings.id, listings.description, listings.search_text, listings.image, listings.date, listings.price, listings.location_city, listings_extra.name, listings_extra.value, listings_extra.classified_id FROM listings,listings_extra WHERE name = 'ISBN%3A'") or die(mysql_error()); while ($fetch_extra = mysql_fetch_array($query_search_exact_match)) { $replace = array("-","ISBN",":"); $with_this = array("","",""); $valu = $fetch_extra['value']; //echo urldecode($fetch_extra['value'])."<br>"; $new_isbn = urldecode(str_replace($replace, $with_this,$valu)); $find_replace = array("-"," "); $find_with_this = array("",""); $find_valu = $_GET['isb']; $to_find_isbn = str_replace($find_replace, $find_with_this,$find_valu); if($new_isbn == $to_find_isbn) { if($fetch_extra['classified_id'] == $fetch_extra['id']) { echo $fetch_extra['title']; } } } Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-764061 Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 You know that ISBNs are no longer 10 digit? Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-764065 Share on other sites More sharing options...
trq Posted February 17, 2009 Share Posted February 17, 2009 Just as an example, string replacements can be done in sql. UPDATE listings_extra SET name = REPLACE(name,'-',''); Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-764087 Share on other sites More sharing options...
jeger003 Posted February 17, 2009 Author Share Posted February 17, 2009 You know that ISBNs are no longer 10 digit? true, but that began i think after 2007. but it really doesn't matter how many digits a user enters....its being able to match isbn's when users search for them.....thats why i wanted to remove the '-'. Just as an example, string replacements can be done in sql. UPDATE listings_extra SET name = REPLACE(name,'-',''); this is a very help tip......only problem is that i'd probably have to update the db every time a user enters a book. is there any thing in php or mysql that would remove/ignor everything except numbers? Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-764297 Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 I store all ISBNs as 13 character strings (no dashes). I also convert old ones to new format for storage. I don't have search by ISBN functionality, but it could be easy to do searching either for all 13 digits, or for 9 digits from old format, basing on number of digits entered by user. Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-764305 Share on other sites More sharing options...
jeger003 Posted February 17, 2009 Author Share Posted February 17, 2009 I store all ISBNs as 13 character strings (no dashes). I also convert old ones to new format for storage. I don't have search by ISBN functionality, but it could be easy to do searching either for all 13 digits, or for 9 digits from old format, basing on number of digits entered by user. i thought each isbn was assigned to a specific book......how can a 9 digit be converted to a 13 digit? i think what im going to do is offer two fields......ISBN 13: and ISBN 10: this way there wont be a mix up on which is which.....i dont know why a user would think they can put (ISBN13:978-11-335-44) in a field that asks for ISBN:(meaning just the numbers)....theyr just putting double the crap (ISBN:ISBN13:978-11-335-44)...this is where it really messes up the search and makes it incredibly difficult to remove ISBN13 then search for 978-....do you have any similar issues? EDIT: and how do you get around them? Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-764320 Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 Each ISBN10 can be converted to ISBN13 by adding 978 at the beginning and recalculating the last digit according to EAN13 algorithm for check digit (ISBN13 is, after all, an EAN13 code). http://en.wikipedia.org/wiki/European_Article_Number You can use JavaScript, to allow only digits into form field (you can in fact even check, if given number is valid ISBN) Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-764327 Share on other sites More sharing options...
jeger003 Posted February 17, 2009 Author Share Posted February 17, 2009 Each ISBN10 can be converted to ISBN13 by adding 978 at the beginning and recalculating the last digit according to EAN13 algorithm for check digit (ISBN13 is, after all, an EAN13 code). http://en.wikipedia.org/wiki/European_Article_Number You can use JavaScript, to allow only digits into form field (you can in fact even check, if given number is valid ISBN) lol that is freakin awesome....i had no idea that was even possible.......thats def something im gonna read up on...........thank you for all the help....greatly appreciate it!!!! Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-764386 Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 Read also wikipedia article about ISBN itself. Some useful info there as well. Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-764388 Share on other sites More sharing options...
jeger003 Posted February 17, 2009 Author Share Posted February 17, 2009 Read also wikipedia article about ISBN itself. Some useful info there as well. yeah thanks so much man! i had no clue about any of this stuff. Link to comment https://forums.phpfreaks.com/topic/145498-solved-how-can-this-be-done-is-it-possible-in-php/#findComment-764475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.