I'm writing code for a school transcript system. However, I'm stuck in joining the tables which are the courses table I named 'causes', courses registered table I named 'courses_registered' and the students table 'students' actually the join works, but the problem is that data are repeated in multiples depending on how many data rows that are on the courses_registered table for example, if have 2 courses registered, I get 4 rows echoed out from all tables instead of two. so my question is, how can i join these three tables perfectly without data being repeated, when i loop through the data. this is the table structure for the three tables.
--
-- Table structure for table `courses`
--
CREATE TABLE IF NOT EXISTS `courses` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`course_code` varchar(255) NOT NULL,
`course_title` varchar(255) NOT NULL,
`cl` int(255) NOT NULL,
`level` int(255) NOT NULL,
`session` varchar(255) NOT NULL,
`semester` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `courses`
--
INSERT INTO `courses` (`id`, `course_code`, `course_title`, `cl`, `level`, `session`, `semester`) VALUES
(1, 'GSS 111', 'Use of English', 3, 1, '2009/2010', '1'),
(2, 'GSS 112', 'Nigerian History', 2, 1, '2009/2010', '1');
--
-- Table structure for table `courses_registered`
--
CREATE TABLE IF NOT EXISTS `courses_registered` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`course_id` int(255) NOT NULL,
`student_id` int(255) NOT NULL,
`score` int(255) NOT NULL,
`grade` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `courses_registered`
--
INSERT INTO `courses_registered` (`id`, `course_id`, `student_id`, `score`, `grade`) VALUES
(1, 1, 2, 60, 'B'),
(2, 2, 2, 80, 'A');
-- --------------------------------------------------------
--
-- Table structure for table `students`
--
CREATE TABLE IF NOT EXISTS `students` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`regno` varchar(255) NOT NULL,
`college` varchar(255) NOT NULL,
`dept` varchar(255) NOT NULL,
`level` varchar(255) NOT NULL,
`fname` varchar(255) NOT NULL,
`lname` varchar(255) NOT NULL,
`no_of_semesters` int(255) NOT NULL,
`gender` varchar(255) NOT NULL,
`dob` varchar(255) NOT NULL,
`age` int(255) NOT NULL,
`mstatus` varchar(255) NOT NULL,
`nationality` varchar(255) NOT NULL,
`religion` varchar(255) NOT NULL,
`address` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`phone` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `students`
--
INSERT INTO `students` (`id`, `regno`, `college`, `dept`, `level`,
`fname`, `lname`, `no_of_semesters`, `gender`, `dob`, `age`,
`mstatus`, `nationality`, `religion`, `address`, `email`, `phone`)
VALUES
(2, 'MOUAU 09/14508', 'CEET', 'Electrical Electronics Engineering',
'1', 'Nnamdi', 'Okoro', 2, 'Male', '24-07-1989', 25, 'Single',
'Nigerian', 'christian', 'Okpu Umiobo road, Aba',
'nokoro#gmail.com', '09056733333');
Then this is the query
<?php
$sql = "
SELECT c.id as course_id
, c.course_code
, c.course_title
, c.cl
, c.level
, c.session
, c.semester
, r.id as rid
, r.course_id
, r.student_id
, r.score
, r.grade
, s.id
, s.regno
, s.fname
, s.lname
, s.no_of_semesters
FROM courses_registered r
JOIN courses c
ON r.course_id = course_id
JOIN students s
ON s.id = r.student_id
WHERE s.id = '$id'
";
$result = mysqli_query($con,$sql) or die ('Could not show students records.'. mysqli_error($con) );
if (mysqli_num_rows($result) > 0 ){
//echo mysqli_num_rows($result);
while($row = mysqli_fetch_array($result) ){
$score[] = $row['score'];
$course_code[] = $row['course_code'];
$course_title[] = $row['course_title'];
$cl[] = $row['cl'];
$grade[] = $row['grade'];
}
Try change this
ON r.course_id = course_id
to
ON r.course_id = c.id
Related
i have these set of tables
CREATE TABLE `staff` (
`id` mediumint(8) NOT NULL AUTO_INCREMENT,
`uid` varchar(128) NOT NULL,
`name` varchar(128) NOT NULL,
`deptname` varchar(128) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `staff` (`id`, `uid`, `name`, `deptname`) VALUES
(1,'A100','John','Finance'),
(2,'A101','Joana','ICT'),
(3,'A103','Darrel','Maintenance'),
(4,'A104','Smith','HR');
CREATE TABLE `department` (
`id` mediumint(8) NOT NULL AUTO_INCREMENT,
`deptid` int(11) UNSIGNED NOT NULL DEFAULT '0',
`deptname` varchar(128) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `department` (`id`, `deptid`, `deptname`) VALUES
(1,'100','ICT'),
(2,'200','Finance'),
(8,'300','HR'),
(11,'400','Maintenance'),
(12,'500','Backup');
CREATE TABLE `new_staff` (
`id` mediumint(8) NOT NULL AUTO_INCREMENT,
`uid` varchar(128) NOT NULL,
`name` varchar(128) NOT NULL,
`deptid` int(11) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `new_staff` (`id`, `uid`, `name`, `deptid`) VALUES
(1,'A100','John','600'),
(2,'A103','Darrel','400'),
(3,'A104','Smith','300'),
(4,'A101','Joana','500'),
(5,'A105','Fran','800');
i would like to update the deptid field in the new_staff table to have the correct deptid as listed in the department table
in the new_staff table deptid are currently wrong for John and Joana
this is what i tried so far
// list all deptid exists
$result=$mysqli->query("SELECT deptid FROM department");
while ($rows=mysqli_fetch_array($result))
{$deptid[]=$rows['deptid'];}
$deptidarray = implode(', ', $deptid);
echo "<br>";
//echo "$deptidarray<br>";
$query=$mysqli->query("SELECT deptid from new_staff WHERE deptid not in ($deptidarray)");
echo "<br>";
$rowtotal = mysqli_num_rows($query);
if($rowtotal>0){
while ($row=mysqli_fetch_array($query))
{
$deptid=$row['deptid'];
// echo "$deptid,";
//$query=$mysqli->query("UPDATE new_staff set deptid='$deptid' WHERE ");
}
}
else
{
// not found
}
is this possible to do entirely in mysql?
UPDATE new_staff AS ns
JOIN staff AS s ON
ns.uid = s.uid // 1. Get same users from 2 tables
JOIN department AS d ON
s.deptname = d.deptname // 2. Get department
SET ns.deptid = d.deptid // 4. Update correct department id
WHERE ns.deptid != d.deptid; // 3. Get users where department is incorrect
Run SELECT query first before updating to verify the updates.
SELECT ns.*, d.deptid AS new_dept_id
FROM new_staff AS ns
JOIN staff AS s ON
ns.uid = s.uid
JOIN department AS d ON
s.deptname = d.deptname
WHERE ns.deptid != d.deptid;
There I have some multiple query and want to execute in Codeigniter.
Below are the code I tried.
function seememberfilter($course,$n)
{
$this->load->database();
$sql = array();
$sql[] = "CREATE TEMPORARY TABLE temp1";
$sql[] = "select id,rand, name,lname, email,phone from `member` where course like ('%$course%')";
$sql[] = "CREATE TEMPORARY table temp2";
$sql[] = "select distinct t.id,t.rand, t.name,t.lname, t.email,t.phone, a.quest_id from temp1 t left join assignment a on t.rand= a.rand";
$sql[] = "CREATE TEMPORARY table randid";
$sql[] = "select rand, quest_id from temp2 where quest_id=$n";
$sql[] = "select t.id,t.rand, t.name,t.lname, t.email,t.phone, r.quest_id from temp1 t left join randid r on t.rand= r.rand";
foreach ($sql as $sql_command)
{
if ($debugging == 0)
{
$this->db->query($sql_command);
}
elseif ($debugging == 1)
{
echo $sql_command;
}
}
return $query->result();
}
Above code is in model and below code is in Controller
public function assign(){
$this->load->model("user_model");
$course=$this->input->post('course');
$n=$this->input->post('id');
$data['sel'] = $this->user_model->seememberfilter($course,$n);
$this->load->view('assign',$data);
}
mysql query are executing well in phpmyadmin. I checked it
What I want: I want to execute mysql query in CI successfully .
I am editing this and giving you sql table complete details
DROP TABLE IF EXISTS `member`;
CREATE TABLE IF NOT EXISTS `member` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`rand` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
`lname` varchar(255) NOT NULL,
`phone` varchar(255) NOT NULL,
`dob` varchar(255) NOT NULL,
`course` text NOT NULL,
`gender` varchar(255) NOT NULL,
`address` varchar(255) NOT NULL,
`city` varchar(255) NOT NULL,
`state` varchar(255) NOT NULL,
`zip` varchar(255) NOT NULL,
`comment` text NOT NULL,
`Aboutme` text NOT NULL,
`dat` varchar(255) NOT NULL,
`tim` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
INSERT INTO `member` (`id`, `rand`, `email`, `name`, `lname`, `phone`, `dob`, `course`, `gender`, `address`, `city`, `state`, `zip`, `comment`, `Aboutme`, `dat`, `tim`) VALUES
(1, 'jrf20180961828', 'kk122344545#hotmail.com', 'Kishan', 'Yadav', '9717111111', '2018-09-01', 'paper first,Political Science,Philosophy,', 'male', 'Diamond Auto Mobiles', 'Belthara road', 'ballia', '221715', 'Good person.', '', '06-09-2018', '11:24:16pm'),
(2, 'jrf20180914721', 'kk1#gmail.com', 'Rohan', 'Yadav', '9717111111', '2018-09-01', 'paper first,Philosophy,History,', 'male', 'Diamond Auto Mobiles', 'Belthara road', 'ballia', '221715', 'Good Person.', '', '06-09-2018', '11:25:44pm'),
(5, 'jrf20180958284', 'ykishan94612121#gmail.com', 'kiran', 'Singh', '9717111111', '2018-07-07', 'paper first,Political Science,History,', 'female', 'Diamond Auto Mobiles', 'Belthara road', 'ballia', '221715', 'nnbmnm', '', '10-09-2018', '10:11:34pm'),
(4, 'jrf20180932851', 'kk12#gmail.com', 'Pankaj', 'Yadav', '9717111111', '2018-09-01', 'paper first,Philosophy,Psychology,History,', 'male', 'Diamond Auto Mobiles', 'Belthara road', 'ballia', '221715', 'nmbmbn', '', '10-09-2018', '10:10:19pm'),
(6, 'jrf20180929250', 'hjh#gmail.com', 'John', 'Corter', '9717111111', '2018-09-06', 'paper first,History,', 'male', 'Diamond Auto Mobiles', 'Belthara road', 'ballia', '221715', 'sxs', '', '11-09-2018', '12:09:49am');
COMMIT;
And second table is
DROP TABLE IF EXISTS `assignment`;
CREATE TABLE IF NOT EXISTS `assignment` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`rand` varchar(255) NOT NULL,
`course` varchar(255) NOT NULL,
`quest_id` varchar(255) NOT NULL,
`time` varchar(255) NOT NULL,
`date` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
INSERT INTO `assignment` (`id`, `rand`, `course`, `quest_id`, `time`, `date`) VALUES
(1, 'jrf20180914721', 'paper first', '2', '10:05:48pm', '2018-09-10'),
(2, 'jrf20180961828', 'paper first', '2', '10:06:49pm', '10-09-2018'),
(3, 'jrf20180914721', 'History', '2', '10:08:03pm', '10-09-2018'),
(4, 'jrf20180958284', 'History', '2', '10:12:05pm', '10-09-2018'),
(5, 'jrf20180914721', 'paper first', '1', '10:19:23pm', '10-09-2018'),
(6, 'jrf20180932851', 'History', '3', '12:07:48am', '11-09-2018');
COMMIT;
And my output should be kind of this, I join two table to get this output.
Attached pic of my output
I get this output using above query. Sorry for my english.
After chat in db-fiddle:
select distinct t.id, t.rand, name, lname, email, phone, if(quest_id='2','2',NULL) as quest-id
from `member` t
left join assignment a on t.rand= a.rand
where t.course like '%History%'
and (a.course like '%History%') or a.id is null
Member constrained to course, assignment same course, quest(ion)_id 2 displayed if it was found, otherwise leave the field as NULL.
You can use transaction to separate Query execution
$this->db->trans_start();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');
$this->db->trans_complete();
My database has five tables:
Computer|Mobile|Tablet|MusicSystem|Camera
All the tables are in same structure like:
productID|ProductBrand|Price|userId
Here, I want to search product's brand name in all the field of productBrand in all the tables, where userId=$userId and limit is 10 then display it with pagination technique.
How can I create such a query in MySQLi and display it in PHP?
Thanks in advance.
try this...
select * from Computer c,Mobile m,Tablet t,MusicSystem ms,Camera cam where userId = $userId and (c.productBrand = searchingProductBrand or m.productBrand = searchingProductBrand or t.productBrand = searchingProductBrand or ms.productBrand = searchingProductBrand or cam.productBrand = searchingProductBrand ) limit 10
If you are following same structure for each category table,better structure is to categorize all into single table as follows
CREATE TABLE IF NOT EXISTS `category` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`category_name` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
INSERT INTO `category` (`id`, `category_name`) VALUES
(1, 'Computer'),
(2, 'Mobile'),
(3, 'Tablet'),
(4, 'MusicSystem'),
(5, 'Camera');
CREATE TABLE IF NOT EXISTS `products` (
`ProductId` int(11) NOT NULL AUTO_INCREMENT,
`ProductBrand` varchar(255) NOT NULL,
`Price` varchar(100) NOT NULL,
`UserId` int(11) unsigned NOT NULL,
`CatId` int(11) unsigned NOT NULL,
PRIMARY KEY (`ProductId`),
KEY `CatId` (`CatId`),
CONSTRAINT `products_ibfk_1` FOREIGN KEY (`CatId`) REFERENCES `category` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
INSERT INTO `products` (`ProductId`, `ProductBrand`, `Price`, `UserId`, `CatId`) VALUES
(1, 'Lenovo', '35000', 5, 3),
(2, 'Asus', '28350', 5, 2),
(3, 'Dell', '25000', 5, 3),
(4, 'MotoG', '12500', 5, 2),
(5, 'Samsung', '52000', 4, 1);
You can get your result using
SELECT * FROM products WHERE userId = '5'
Check the FIDDLE
I have a Search page where users can search based on certain criteria. I cannot get the query right to display only one of the desired objects. It is displaying multiple entries for specified criteria. Here is our database setup:
CREATE TABLE Class
(
cid int NOT NULL,
classNum int,
classDept varchar(20),
PRIMARY KEY (cid)
);
CREATE TABLE Book
(
bid int NOT NULL,
cid int NOT NULL,
title varchar(20) NOT NULL,
author varchar(20) NOT NULL,
isbn varchar(13),
price decimal(5,2) NOT NULL,
PRIMARY KEY (bid),
FOREIGN KEY (cid) REFERENCES Class (cid)
);
CREATE TABLE Contact
(
contactID int NOT NULL,
fname varchar(20),
lname varchar(20),
contactInfo varchar(90) NOT NULL,
PRIMARY KEY (contactID)
);
CREATE TABLE Post
(
pid int NOT NULL,
contactID int NOT NULL,
bid int NOT NULL,
postDate date,
PRIMARY KEY (pid),
FOREIGN KEY (contactID) references Contact(contactID),
FOREIGN KEY (bid) references Book(bid)
);
Here is the php code we are using to try to query based on criteria the user has entered.
$author = $_POST["author"];
$title = $_POST["title"];
$classNum = $_POST["number"];
$classDept = $_POST["department"];
$isbn = $_POST["isbn"];
$query = "SELECT title, author, isbn, price, classNum, classDept, contactInfo
FROM Book, Class, Contact, Post
WHERE Book.cid=Class.cid AND Contact.contactID=Post.ContactID and Book.bid=Post.bid AND Book.author='$author' OR Book.title='$title' ";
$stid = oci_parse($conn,$query);
oci_execute($stid,OCI_DEFAULT);
What are we doing wrong? How can we get the proper search results to display?
I'm not entirely sure that the join syntax in Oracle is the same as mysql ( which is what this was built and tested in ) but given the dummy data and minor modifications to some tables ( adding auto_increment to primary keys ) it returns the expected two rows that match the params.
create table if not exists `book` (
`bid` int(11) not null auto_increment,
`cid` int(11) not null,
`title` varchar(64) not null,
`author` varchar(20) not null,
`isbn` varchar(13) default null,
`price` decimal(5,2) not null,
primary key (`bid`),
key `cid` (`cid`),
constraint `book_ibfk_1` foreign key (`cid`) references `class` (`cid`)
) engine=innodb auto_increment=5 default charset=utf8;
insert into `book` (`bid`, `cid`, `title`, `author`, `isbn`, `price`) values
(1, 1, 'deranged dahlias', 'gertrude geikel', '1234-cdbs-9d', 250.00),
(2, 1, 'mental magnolias', 'gertrude geikel', '4234-cdfg-9f', 225.00),
(3, 1, 'raging roses', 'gertrude geikel', '4389-fkpl-8d', 120.25),
(4, 3, 'peaceful petunias', 'alice cooper', '9043-dflk-01', 500.25);
create table if not exists `class` (
`cid` int(11) not null auto_increment,
`classnum` int(11) default null,
`classdept` varchar(20) default null,
primary key (`cid`)
) engine=innodb auto_increment=4 default charset=utf8;
insert into `class` (`cid`, `classnum`, `classdept`) values
(1, 404, 'fookology'),
(2, 403, 'forbidden fruits'),
(3, 200, 'goodness');
create table if not exists `contact` (
`contactid` int(11) not null auto_increment,
`fname` varchar(20) default null,
`lname` varchar(20) default null,
`contactinfo` varchar(90) not null,
primary key (`contactid`)
) engine=innodb auto_increment=3 default charset=utf8;
insert into `contact` (`contactid`, `fname`, `lname`, `contactinfo`) values
(1, 'joe', 'bloggs', 'chief headbanger'),
(2, 'fred', 'flintstone', 'potatopeeler');
create table if not exists `post` (
`pid` int(11) unsigned not null auto_increment,
`contactid` int(11) not null,
`bid` int(11) not null,
`postdate` date default null,
primary key (`pid`),
key `contactid` (`contactid`),
key `bid` (`bid`),
constraint `post_ibfk_1` foreign key (`contactid`) references `contact` (`contactid`),
constraint `post_ibfk_2` foreign key (`bid`) references `book` (`bid`)
) engine=innodb auto_increment=3 default charset=utf8;
insert into `post` (`pid`, `contactid`, `bid`, `postdate`) values
(1, 1, 1, '2015-12-02'),
(2, 2, 4, '2015-12-02');
Query run in mysql gui - not sure if the join syntax is the same in oracle .
set #_author='alice cooper';
set #_title='mental magnolias';
select * from `book` b
left outer join `class` c on c.`cid`=b.`cid`
left outer join `post` p on p.`bid`=b.`bid`
left outer join `contact` ct on ct.`contactID`=p.`contactID`
where b.`title`=#_title or b.`author`=#_author;
Or, for php
$author=$_POST['author'];
$title=$_POST['title'];
$sql="select * from `book` b
left outer join `class` c on c.`cid`=b.`cid`
left outer join `post` p on p.`bid`=b.`bid`
left outer join `contact` ct on ct.`contactID`=p.`contactID`
where b.`title`='{$title}' or b.`author`='{$author}';";
I have these two table with some data sample in them. I would like to to pull out number of classifieds in each category. I gave it a try, and I got (2) in each one which is not correct. So hopefully someone will help me with this.
CREATE TABLE IF NOT EXISTS `categories` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8_unicode_ci NOT NULL,
`subcategory_id` int(2) NOT NULL DEFAULT '0',
`parent_id` int(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=27 ;
--
-- Dumping data for table `categories`
--
INSERT INTO `categories` (`id`, `name`, `subcategory_id`, `parent_id`) VALUES
(1, 'Announcements', 0, 0),
(2, 'Employment', 0, 0),
(3, 'Items For Sale', 0, 0),
(4, 'Services', 0, 0),
(5, 'Garage Sales', 0, 0),
(6, 'Automobiles', 0, 0),
(7, 'Announcement1', 1, 1),
(8, 'Announcement2', 1, 1),
--
-- Table structure for table `classifieds`
--
CREATE TABLE IF NOT EXISTS `classifieds` (
`classified_id` int(255) NOT NULL AUTO_INCREMENT,
`title` text COLLATE utf8_unicode_ci NOT NULL,
`description` text COLLATE utf8_unicode_ci NOT NULL,
`category_id` int(10) NOT NULL,
`name` text COLLATE utf8_unicode_ci NOT NULL,
`authorized` int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (`adid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=177 ;
--
-- Dumping data for table `classifieds`
--
INSERT INTO `classifieds` (`classified_id`, `title`, `description`, `category_id`, `name`, `authorized`) VALUES
(1, 'Test Classified', 'Here is the First Test classified listing.', 1, 1);
INSERT INTO `classifieds` (`classified_id`, `title`, `description`, `category_id`, `name`, `authorized`) VALUES
(2, 'GMC For Sell', 'Looks like new 1979 GMC.', 6, 1);
here
$query = "SELECT category_id, COUNT(title) FROM classifieds GROUP BY category_id";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result)
$num_items_in_category = $row['COUNT(title)'];
echo "<><a href='category-".$row['id'].".php' >".$row['name'].$num_items_in_category."</a></li>";
Thanks
Change the SQL a bit, and loop through the results?
$query = "SELECT c.id, c.name,
COUNT(cl.category_id) AS num_items_in_category
FROM category_id c
LEFT JOIN aclassifieds cl ON cl.category_id=c.id
GROUP BY c.id";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo "<li><a href='category-".$row['id'].".php' >".$row['name'].$row['num_items_in_category']."</."</a></li>";
}
Just in case someone else wants to benefit my this:
enter $query = "SELECT c.id, c.name,
COUNT(cl.title) AS num_items_in_category
FROM categories c
LEFT JOIN classifieds cl ON cl.category_id=c.id
GROUP BY c.id";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo "".$row['name'].$row['num_items_in_category']."";
}
here
Thanks