Form show select box after choice option on select [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I intend that after selecting an option from a list, a new list appears according to the option selected.
But the second select list, sends a query to the database, depending on the choice list in the first select!
example:
table bd
| A | 1 |
| A | 2 |
| B | 3 |
| B | 4 |
first select
A or B
second select
if select A
1
2
if select B
3
4

A simple search for a filtered dropdown list brought me to the following code on GitHub which does a decent job explaining how to program one of these lists on your own. You can find it here.
Hope this helps.

Related

Is there a way to count repeated strings in records from a MySQL Table? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
I want to know if there is a way to count repeated strings in diferent records in a MySQL table, for instance, given a table like this one:
+----+-----------------------+
| id | data |
+----+-----------------------+
| 1 | this is here |
+----+-----------------------+
| 2 | this would be nice |
+----+-----------------------+
| 3 | this was here |
+----+-----------------------+
| 4 | this needs to be said |
+----+-----------------------+
I'd like the following result:
Count: this(4), here(2)
This is what I've been looking for, but no luck until now.
You can start with this:
SELECT id, data, SUBSTRING_INDEX(SUBSTRING_INDEX(data,' ',x.x),' ',-1) as Y
FROM test
CROSS JOIN (select 1 as x union select 2 union select 3 union select 4) x
ORDER BY id, x.x
see: DBFIDDLE
output:
id
data
Y
1
this is here
this
1
this is here
is
1
this is here
here
1
this is here
here
2
this would be nice
this
2
this would be nice
would
2
this would be nice
be
2
this would be nice
nice
3
this was here
this
3
this was here
was
3
this was here
here
3
this was here
here
4
this needs to be said
this
4
this needs to be said
needs
4
this needs to be said
to
4
this needs to be said
be
Things left to be done:
Check If you have more, of less than, 4 words. Currently when you only have 3 word the last word is repeated, and when having more than 5 words they are ignored.
Count the stuff, but that is basic SQL stuff using count(*)
BONUS: Getting the number of words in a string:
SELECT
id,
data,
length(data)-length(replace(data,' ',''))+1 as NrOfWords
from test;
output:
id
data
NrOfWords
1
this is here
3
2
this would be nice
4
3
this was here
3
4
this needs to be said
5

How to set display multiple data under one perticular field [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
This is my sql outcome:
What I am trying to achieve is to show the garden and under that it shows the hose pipe ,lawn moar etc.
How to write the query?
If I understand you correct you would normaly do that somehow like that.
cat_id | parent_id | cat_name | cat order
1 0 Garden 1
2 1 Hose Pipe 1
3 1 Lawn Moar 2
in this case Garden for example would have the cat_id 1 and parent_id 0 and all subcategories have their own incremented id and the parent_id of garden, which would be 1 in this case!
then you can query for your categories and foreach of them query for the subcategories where the parent_id is the cat_id of the maincategory!
here you have a nice tutorial on how to display it recursive:
https://www.codexworld.com/dynamic-category-subcategory-tree-php-mysql/
that way you also only need to save the imagepath only once in your maincat!

Delete and Insert vs Update rows on table [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I have a web form in when the user can select many available items (idFamilia) for a single Provider (idProveedor) that looks like this
The values are saved in this table
-----------------------------
| idProveedor | idFamilia |
-----------------------------
| 5 | 1 |
-----------------------------
| 5 | 2 |
-----------------------------
| 6 | 2 |
-----------------------------
After a Provider is created, it can be edited and the values selected for idFamilia can be changed. So I have three different scenarios of what could happen:
The numbers of rows remain the same and I would only need to edit the values of idFamilia.
Some items were deleted from the selection and I would need to search the values on the table and delete those rows.
New items are added and I would need to insert those additional values.
Right now I am thinking about just deleting all the rows with the idProveedor that is being edited and just insert the new selection.
Is this a good practice? Will this affect the performance on the long run?
Could you recommend a tutorial or example to do it the other way?
I always go the way to delete and re-create them.
While this adds some performance penalty, it keeps the code simple to understand and easy to maintain. Unless you're Uber, Google, Facebook, Amazon, or other world scale app, the benefits you'd get from optimizing this are much smaller than the cost it incurs: in development, debugging and maintenance time.

MySQL query to get one of each Item [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am working with php and MySQL, I am making a messaging app, the app has communicates with a remote database, in my database is my messaging table, the table has 9 tables of which includes the "Subject table", I need help, I want to make a query that retrieves only one subject of each type, lets say I have 10 messages with the subject "Man", 12 of the "Dog", I want it to get only one man and one dog below is a graphic representation of my Messaging Table.
| message_id | subject | username |
|:-----------|------------:|:------------:|
| 1 | cyber | Chrome |
| 2 | Hyper | Ciare |
| 4 | Cyber | Gorger |
You can use SQL's DISTINCT:
SELECT DISTINCT subject FROM table
This will fetch each subject only one time, even if it appers more than once.

How to store daily hits for items using MySQL and PHP? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
In my MySQL database, I'm trying way of creating a table to track daily views on 100 items. Each day would insert a new row for each item. So the table columns would look like this:
| ItemID | ItemName | Hits |
Is there a way to store daily hits for items?
What you could do is have a table with a structure like:
| item_hits |
|---------------|
| itemID | date |
Then your SQL query could look like
SELECT count(*) FROM item_hits WHERE date = '2015/04/15' and itemID = 7;
You wouldn't need to save the itemName in the table, because you should be able to get the itemName by joining it to your items table.

Categories