How to set display multiple data under one perticular field [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 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!

Related

How to delete the specific database value [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 1 year ago.
Improve this question
Below is my SQL table
| ID | Value |
| 1 | A1 A2 A3 |
I would like to delete the A3 in the column: Value. Is there any method to do this?
There's no way to edit/remove part of string, you just need to update whole cell. It's up tou you, how you'll prepare update data in your code.
SQL:
update tablename set Value = 'A1 A2' where ID=1

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.

Zend db Mysql sorting by count [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 8 years ago.
Improve this question
I'm looking for the right syntax using Zend db to show a table that is sorted by the count. For example, my mysql table looks like this:
Users Description
1 topic1
1 topic2
2 topic3
I want the output to look like:
User 1 (2 descriptions)
User 2 (1 description)
The raw query you're looking for
SELECT users, COUNT(*) count
FROM table1
GROUP BY users
ORDER BY COUNT(*) DESC
Output:
| USERS | COUNT |
|-------|-------|
| 1 | 2 |
| 2 | 1 |
Here is SQLFiddle demo
I'm not an expert in Zend but your query may look something between the lines of
$select = $db->select()
->from('table1', array('users', 'count' => '(COUNT(*))'))
->group('users')
->order('(COUNT(*)) DESC');
$stmt = $db->query($select);
$result = $stmt->fetchAll();

Select only one number from array MySQL PHP [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 9 years ago.
Improve this question
i have the following query bellow
SELECT * FROM subcat where catid in (2) order by id desc
what i am trying to do is select one number only in catid i have ex:
1,2,3,4,5
this work but only when "catid" start with number "2" then have ","
example
ID | 1
subcat_name | PHP
catid | 2,3,4
ID | 2
subcat_name | ASP
catid | 5,2,3
ID | 3
subcat_name | MYSQL
catid | 6
ID | 4
subcat_name | C++
catid | 2
i want to select the subcat with only catid = 2
Try this
SELECT * FROM subcat where FIND_IN_SET(2,catid) order by id desc

Form show select box after choice option on select [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 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.

Categories