Jump to content

[SOLVED] how can this be done? is it possible in php?


jeger003

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.