First I should say my English is not perfect. I am using XAMPP 5.6.0.0
I have two tables, services and services_cat.
-- Table structure for table `services_cat`
CREATE TABLE IF NOT EXISTS `services_cat`
(`ser_cat_id` int(11) NOT NULL,
`service_category` varchar(50) NOT NULL)
-- Table structure for table `services`
CREATE TABLE IF NOT EXISTS `services`
(`service_id` int(11) NOT NULL,
`scid` int(11) NOT NULL,
`service_title` varchar(50) NOT NULL,
`service_statement` varchar(1000) NOT NULL,
`service_photo` varchar(100) NOT NULL)
I want to show following data in one table.
service_id
ser_cat_id
service_category
service_title
service_statement
ser_cat_id and service_id are PRIMARY KEYs.
here ser_cat_id save into scid in the services table. This ser_cat_id save multiple times in the scid colomn. But service_title will be changed. There are different types of service_title, but the scid is same for that different service_titles. That scid comming from ser_cat_id from services_cat table.
I can pass ser_cat_id to scid from service_cat table and I can fetch (display) that scid. But I want to display that DISTINCT service_category name of the ser_cat_id(same as scid in services table).
Can you please help me ..
Following is my code.
<?php
include_once("conn.php");
$sql = mysql_query("SELECT * FROM services_cat JOIN services ON services_cat.ser_cat_id = services.service_id GROUP BY service_category ");
while($row = mysql_fetch_object($sql))
{
echo "<tr>
<td><p class='table-p'>$row->scid</p></td>
<td><p class='table-p'>$row->ser_cat_id</p></td>
<td><p class='table-p'>$row->service_category = $row->scid</p></td>
<td><p class='table-p'>$row->service_title</p></td>
<td><p class='table-p'>$row->service_statement</p></td>
<td><p class='table-p'><a href='service_edit.php?ide=$row->service_id'>Edit</a> |
<a href='service_delete.php?idd=$row->service_id'>Delete</a></p></td>
";
}
?>
ser_cat_idmay have severalservice_category? otherwise your query is correct. I believe you want to recieve DISTINCTservice_titlenotservice_categoryservices_cat.ser_cat_id = services.scid?ser_cat_idhave manyservice_categoryEx ::ser_cat_id=1service_category=Decoration,,,,,,ser_cat_id=2service_category=Dressing......ser_cat_id=3service_category=Dancingetc..ON services_cat.ser_cat_id = services.scid, as @Berriel said. So, any joined query you do will have the same values for those two fields.