The table structure
Code: Select all
CREATE TABLE my_docs (
id int auto_increment,
title varchar (150) not null,
catid int not null,
intro text not null,
doc longtext not null,
primary key (id),
unique id (id)
);101 is computer science
1011 is programming
1012 is operating system
10111 is ASP
10112 is JavaServlet
10113 is Perl
10114 is PHP
102 is music
1021 is world wide music
1022 is nation music
and so on...
When certain user click on computer science link, we have to show them articles in computer science section and thus we do the following
Code: Select all
<?php
$computer_science = mysql_query ("SELECT * FROM my_docs WHERE catid=101 AND catid=1011 AND catid=1012 AND catid=10111 AND catid=10112 AND catid=10113 AND catid=10114 ORDER BY id DESC LIMIT 9");
while ($cdata = mysql_fetch_array($computer_science)) {
echo "
<p><b>$cdata[title]</b>
<p>$cdata[intro]
<p>$cdata[doc]
";
}
?>But poor me, I dunno how to refine it.
Any solution for that?
Can PHP looks into the CATID column, searching for only three begining digits then putting it into the SQL statement so that we don't have to AND and AND and AND too many times?