Jump to content

using regex with mysql


jeger003

Recommended Posts

hello,

i have a search on my site that matches a users ISBN entered with the one in my database

 

i want to figure out a way to use regex to match isbn numbers only

 

ie

SELECT * FROM table WHERE isbn REGEX(numbers) $user_entered_isbn

 

so say that the database has an isbn stored as ISBN97345444 whatever and the user enters 97345444 in the search

i want this to be a match of numbers

 

is this possible??

 

thank you guys

Link to comment
Share on other sites

is there a way to get this to work to match only numbers?

 


$query_search_exact_match = mysql_query("SELECT 
							nvc_classifieds.title, 
							 nvc_classifieds.id,
							nvc_classifieds.description, 
							 nvc_classifieds.search_text, 
							 nvc_classifieds.image, 
							nvc_classifieds.date, 
							nvc_classifieds.price,
							nvc_classifieds.location_city,
							nvc_classifieds_ads_extra.name,
							nvc_classifieds_ads_extra.value,
							nvc_classifieds_ads_extra.classified_id
   
									FROM   	nvc_classifieds_ads_extra
									JOIN 	nvc_classifieds 
									ON 		nvc_classifieds.id = nvc_classifieds_ads_extra.classified_id
									WHERE  	nvc_classifieds_ads_extra.name = 'ISBN%3A'
									AND 	live=1 
									AND  	(nvc_classifieds_ads_extra.value 
									REGEXP '[0-9] $search_isbn') 
									") or die(mysql_error());

 

using REGEXP - i want it to match only numbers but It does not

 

anyone have any ideas?

Link to comment
Share on other sites

  • 3 weeks later...

I'm not convinced you need regex for this...regex is pattern matching... it looks like you are wanting to select info from the database based on a number the user enters in...for example, you have the following:

 

[pre]

column: ISBN

------------

  row: ISBN97345444

[/pre]

 

user enters in "97345444" and this value is in $number

 

You would just do something like (simplified sql statement):

 

$sql = "SELECT * FROM TABLENAME WHERE ISBN = 'ISBN{$number}'";

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.