I have a new question cause i didnt find it anywhere.
I have a db which contains 4 columns. I did my bot to insert array to a column.Now i have to fill another columns.
My filled column contains site links. Exmp: www.dizipub.com/person-of-interest-1-sezon-2-bolum-izle
I need to take "person-of-ınterest" part and write it to another column as kind of a "Person of Interest". And also "1-sezon-2-bolum" as "Sezon 1 - Bölüm 1".
I couldnt find it to do with php not sql. I need to make it with bot. Can someone help me about it please.
database
There is a column named bolumlink where i put the links. As i told i need to take some words from these links. For instance:
dizi column needs to be filled with "Pretty Little Liars" in first 9 row.
It can be done by SQL Update with Like which allows you to select rows with pattern based search using wild-cards:
% matches any number of characters, even zero characters.
_ matches exactly one character.
update your_table set dizi = 'Pretty Little Liars' where bolumlink like '%pretty-little-liars%'
NOTE:
Updating your database using like without limit or conditions with unique columns can be dangerous. This code might affect the whole table if empty string is passed.
Related
i have a question about searching in MySQL.I couldn't find answer for long time.
I use symfony 3.1 and i have the next situation:
I have column site_languages (longtext, (DC2Type:simple_array) ) in sql with values (for example) "0,1,7", "11,15,27" etc
So my question is:
how i can select row by site_languages which include in array a search value?
I tried use LIKE, checked REGEXP but for example if i need search by value "1" it will return rows with 11/51/111 etc too.I was thinking about keep values like "[1],[15]" But i think there is exist easier and right solution for it?
If you'd like to solve this issue by using a regex you can use this regex (^|,)1(,|$) to match a 1 that is preceded by a comma and followed by a comma OR the 1 may be preceded by the beginning of the line or end of the line.
You should consider normalizing your DB table but if you insist to keep it this way you can save it as json then retrieve all rows and iterate (bad idea) but is ok if it is a short table
I'm using PHP for a school project and I'm trying to run an SQL query that will return a list of entries in a table where they all contain 8 digits of a 12 digit ID. E.g. I have a string containing "0221122017" and I want to query this to return a list of values that resemble "0221122017XXXX". Is there an easy way to do this? I have not been able to find that carries out this sort of function for an SQL Query. I have no problem with the PHP side and running a query etc. I am really just racking my brains as to how this would be done. I hope I have explained my problem well
Thanks
You can use LIKE
SELECT *
FROM yourTable
WHERE id LIKE '%0221122017%'
LIKE is followed by a pattern string, and % is a wildcard that matches anything.
This probably has a simple solution, although it is made a little more difficult because of the way the database is constructed, it isn't mine. A column in the database has a text value that is of the form text1DDtext2DDtext3, where DD is a delimiter that they through in rather than having a separate table for 0 to n values that go in that column.
There is a search that is executed where what I have to start with is:
"text1","text2", "text3", . . .
All I want to do is build on a query that checks to see if any of the "textn" strings are in the column field, although it would be nice to have a query that also checked to see if all of the search string text values are in the column value. The order in which they are stored in the column can vary, as can the search string. If there was a linked table that just had single values in a column it would not be very hard.
I've just various combinations of IN and LIKE, and that doesn't seem to work.
Thanks.
try:
SELECT columnYouWant FROM dbo.table WHERE UPPER(column) LIKE ('%TEXT%');
I have a tab delimited text file with the first row being label headings that are also tab delimited, for example:
Name ID Money
Tom 239482 $2093984
Barry 293984 $92938
The only problem is that there are 30 some columns instead of 3 so I'd rather not have to type out all the (name VARCHAR(50),...) if it's avoidable.
How would I go about writing a function that creates the table from scratch in php from the text file, and say the function takes in $file_path and $table_name? Do I have to write all the column names again telling mysql what type they are and chop off the top or is there a more elegant solution when the names are already there?
You would somehow need to map the column type to the columns in your file. You could do this by adding that data to your textfile. For instance
Name|varchar(32) ID|int(8) Money|int(10)
Tom 239482 $2093984
Barry 293984 $92938
or something similar. Then write a function thet get's the column name and columntype using the first line and the data to fill the table with using all the other rows. You might also want to add a way to name the given table etc. However, this would probably be as much work (if not more) than creating SQL queries using you text file. Add a create table statement at the top and insert statements for each line. With search and replace this could be done very fast.
Even if you could find a way to do this, how would you determine the column type? I guess there would be some way to determine the type of the columns through checking for certain attributes (int, string, etc). And then you'd need to handle weird columns like Money, which might be seen as a string because of the dollar sign, but should almost certainly be stored as an integer.
Unless you plan on using this function quite a bit, I wouldn't bother spending time cobbling it together. Just fat finger the table creation. (Ctrl-C, Ctrl-V is your friend)
I'm in need of some quick help on matching a field in my database that stores all of the "parent" categories for my online store. Here's an example of how my "parents" are stored in the table via one field named Parent:
MENS MENS-BRANDS MENS-SHIRTS MENS-T-SHIRTS
Here is my query in PHP to perform the call:
$query = "SELECT id FROM $usertable where parent like '".strtoupper($parent)."'";
The problem is, if I am on MENS-BRANDS, this will also return those products who are listed in every other category because it contains the word "MENS." Since all of the parents are stored in one field, how can I make my SQL query only recognize each physical word that is separated by spaces in the field itself, instead of it trying to find every instance of different fragments of a word throughout the field?
I hope this makes sense, and any help is surely appreciated.
Ideally you can change your schema so that you have a separate table linking these categories to your existing entries. This way you can have one row per product and you can easily write a SQL query that looks for the specific word you want without the need for a LIKE match. Added bonus: this will improve performance.
However, if you absolutely cannot change this schema, your best bet is probably to use a regular expression like WHERE parent REGEXP '[[:<:]]MENS[[:>:]]'
I'm here using MySQL regular expressions. If you're using a different database management system the same concept will work, but the exact syntax may be different.