php - Is there a SQLI function that cycles through an array to see if any elements are in a MYSQL row? -
i have little sql table. there 'tags' column has several words separated comma. using php & mysqli take search value , compare it's individual words individual words in tag sql 'tags' column.
it relatively little database. can think of way create seperate column every tag. rather not. if option.
example sql layout, table: books
"title" -- "author" -- "tags"
[potter]-- [j.k.] -- [wizards, wandsnshit,magic] [50 shades]-- [james] -- [boobies, sex] [ulysses]-- [joyce] -- [wtf]
so far direction has been:
//obtains searchvalue html $searchvalue=$_get["searchvalue"]; //turns values individual words array $proxy = $searchvalue; $tags = explode(" ", $proxy); //this need help select * books tags contains (cycle through 'tags' array)
if works correctly, typing "gandalf wizard" should homecoming book "potter". because "wizard" tag of "potter" book.
also while i'm @ it. php function "explode" alter original string or create re-create string alter that?
thanks in advance.
this bad design. let's search on net database normalization.
in book table should unique id (primary key, int, not null, auto increment) field. after that, need create relation table, has tags.
for example:
book table:
id name author
tags table
id book_id tag
after can use:
$sql = "select * books" . " inner bring together tags on tags.book_id = books.id" . " tags.tag = " . mysqli_real_escape_string($_get["searchvalue"]);
or can utilize like
keyword.
note:
i wondering, why lot of developer create 2 variable nothing?
$searchvalue=$_get["searchvalue"]; //turns values individual words array $proxy = $searchvalue; $tags = explode(" ", $proxy);
instead: $tags = explode(" ", $_get["searchvalue");
php mysqli tags
No comments:
Post a Comment