tag system using PHP MySql [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to create tag system for my article. now I have this input with comma separated :
trance, house, electronica, dubstep, club
now I need to INSERT this tags To Tags Table Like This:
ID NAME ArticleId
1 trance 10
2 house 10
3 electronica 10
4 dubstep 10
5 garage 10
And How to Fetch, INSERT, DELETE , UPDATE This tags?!

For FETCH using Group Contact
SELECT GROUP_CONCAT(NAME) As tags FROM table_name WHERE ArticleId= 10;
will return like
trance, house, electronica, dubstep, club
for DELETE use simple delete query
DELETE FROM table_name WHERE name = 'trance'
Also for UPDATE query you can use like below
UPDATE table_name SET name = 'trance' WHERE ID = 1
EDIT
Use INSERT query
foreach($tag as $each_tag) {
INSERT INTO table_name (ID, NAME, ArticleId)
VALUES (1, '.$each_tag.', 10);
}
above is just skeleton map with your original code.
hope this will sure help you.

Related

Search query using php and mysql [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Need help on how to filter search results in the search form using PHP and Mysql.
The form contains six fields Product is textbox, Category is drop down select item, Business in text box user enters and state, city are drop down select item and Landmark is textbox the user enters.
Product or Category or Business is mandatory. So the user may enter any one filed or may fill all the fields.
Now I need to get exact search result based on the input. Please Help me to solve this
Try this:
$query = "select * from table_name where 1 ";
if(!empty($_POST['field1']) ) {
$query .= " AND field1 like '".trim($_POST['field1'])."'";
}
if(!empty($_POST['field2'])) {
$query .= " AND field2 like '".trim($_POST['field2'])."'";
}
// and so on
$result = mysql_query($query);

Select all rows but one [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to show all user information held in a db.
SELECT * FROM member
However i do not want it to select the current user (find by personID)
Is there a way to say select all but not personID XXXX?
Thanks
Use <> or != as an not equal to operator.
SELECT * FROM member WHERE personID <> 123;
SELECT * FROM member WHERE personID != 123;
If you want to exclude multiple IDs:
SELECT * FROM member WHERE personID NOT IN (1,2,3);

MySQL solution for multiple column totals [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I am retrieving multiple records from a table in MySQL. Is there a way that I can retrieve one row which totals each of the columns from this query? I was hoping that there might be an SQL solution, as I'll be repeating the process for many tables as it's being used for a dynamic report.
If there is no SQL solution, is there a way to easily add together all the nested arrays inside of an array? This would achieve the same result, but in PHP.
I can't seem to find any information on either approach.
You can do this using using aggregation. You don't give much guidance on what your query looks like, but something like:
select sum(col1) as sumcol1, sum(col2) as sumcol2, . . .
from t;
Without the group by clause, this returns one row, which is a summary of everything in t.
I am not sure what you exactly want to achieve by reading your question as you did not provide any codes or data. Try the following:
SELECT id, col_1, col_2, col_3, col_4, sum(t.Col)
FROM
(SELECT id, col_1, col_2, col_3, col_4,
SUM(col_1+col_2+col_3+col_4)
AS Col
FROM datas
WHERE id = '1'
GROUP BY id)t
You can see the fiddle here

Replace first instance NULL or ' ' with another value - MySQL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to replace the first instance of a NULl or ' ' value in a column with another value. But only the first instance and nothing else.
So far I've put this together:
UPDATE table_name SET column = CONCAT(REPLACE(LEFT(column , INSTR(column , '')), '', 'new_value'), SUBSTRING(column , INSTR(column , '') +1))
I could replace all the values but I don't want that:
UPDATE table_name SET column = REPLACE (column , 'old_value', 'new_value')
Just try using limit 1
UPDATE table_name SET column='new_value' WHERE column='' limit 1

mysql query to return true if all status for a particular id field is true [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a db table with more than one rows for a same ID filed, with another field STATUS (may be 1 or 0). I want to get the status as 1 if all the STATUS is 1 for a particular ID else 0 if any one STATUS is 0(zero)
You can use MySQL's MIN() function:
For a particular ID:
SELECT MIN(STATUS) FROM my_table WHERE ID = ?
For all ID:
SELECT ID, MIN(STATUS) FROM my_table GROUP BY ID

Categories