Hi All, Need help with something,
Im newish to PHP so have very limited knowledge.

Basically I am making an admin panel for a friends beauty website.
I have two different tables in my database,

categories

+----+----------+
|cID | cCat     |
+----+----------+
|  1 | Skin     |
|  2 | Eye      |
|  3 | Ear      |
|  4 | Waxing   |
|  5 | Massage  |
|  6 | Nail     |
+----+----------+

treatments

+----+-----------+-----+--------+----------+------------+-------+-----------+
|tID | tName     | tCat| tPrice | tPicURL  |tDescription| tTime | tPromote  |
+----+-----------+-----+--------+----------+------------+-------+-----------+
|  1 |Hopi Candle|Ear  | 4.00   |1.jpg     | Sample     | 1hr   | False     |
|  2 |Manicure   |Nail | 5.00   |2.jpg     | Saample    | 2hrs  | True      |
|  3 |Spray Tan  |Skin | 10.00  |3.jpg     | Saaample   | 3hrs  | False     |
+----+-----------+-----+--------+----------+------------+-------+-----------+

I want to loop through the results so they display as follows..

[cCat] or [tCat]
tName - tPrice - (Edit) - (Delete)

So each category(tCat or cCat) is displayed and then all the treatments(tName) and treatments prices(tPrice) are displayed underneath..

How do i do this??
I need an sql command and then need to know how to loop through results.

Thanks.
andrew0136
I will add a page for her so she can add categories and treatments so hense why i need a loop function.

Member Avatar for diafol

First of all, you need to sort out the join fields. You'd do better to use an integer in the tCat:

+----+-----------+-----+--------+----------+------------+-------+-----------+
|tID | tName     | tCat| tPrice | tPicURL  |tDescription| tTime | tPromote  |
+----+-----------+-----+--------+----------+------------+-------+-----------+
|  1 |Hopi Candle|3    | 4.00   |1.jpg     | Sample     | 1.0   | False     |
|  2 |Manicure   |6    | 5.00   |2.jpg     | Saample    | 2.0   | True      |
|  3 |Spray Tan  |1    | 10.00  |3.jpg     | Saaample   | 3.0   | False     |
+----+-----------+-----+--------+----------+------------+-------+-----------+

Also note the tTime - store as float/decimal if poss - using units in field can be a pain - so decide on a 'universal unit' - in this case hrs (or you can choose minutes).

SELECT tID, tName, tPrice FROM treatments

Just loop over and add inputs/buttons for edit and delete on each iteration.
Ensure that each button is indexed to the tID, e.g.

echo "<button name='delete[]' value='$id'>Delete</button>";

Obviously this would be a more complete line in your loop, but it's just for clarity.

Thank you "diafol" to provide useful information for looping and joining tables. I was facing this type of problem in my project. Your reply solved my problem. Thank you once again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.