NullPoiиteя
NullPoiиteя

Reputation: 57312

how to search string stored serialized

I want to search the computer from this table and when i have stored this in database so now can find the string and pass to the query so it this string present in database then show result

i am doing

  1. i am getting the value form the url my url looks like localhost\demo\article.php?filter=computer

    $_GET['filter']

  2. my database is

    id | name |tag
    
    1  |java  |a:2:{i:0;s:8:"Computer";i:1;s:4:"Code"; 
    
    2  |dbms  |a:2:{i:0;s:8:"Computer";i:1;s:4:"dbms"; 
    
    3  |c     |a:2:{i:0;s:8:"elect";i:1;s:4:"Code"; 
    

now i am want to fetch all the row where the computer is present or code

for that i am using the query

$query1 = "SELECT * FROM $tableName WHERE tag='%".$_GET['filter']."%' ";

but its not showing the row having the computer or code..

its like the stackoverflow tag filtration

Upvotes: 0

Views: 704

Answers (2)

Adi
Adi

Reputation: 5169

Solving your problem is by replacing = with like so your query should be

$query1 = "SELECT * FROM $tableName WHERE tag like '%".$_GET['filter']."%' ";

a better way of doing this, is to create extra two tables. One will contain your tags (optional) and the other will contain tagging information.

enter image description here

This article will help you so much

Upvotes: 5

lanzz
lanzz

Reputation: 43158

Normalize your database and you will no longer need to turn a nail with a screwdriver.

Upvotes: 4

Related Questions