There's a bus load of errors in your script just by looking at it at first glance. To focus strictly on the query since that's whats you've
asked for, it looks like your query is on overkill mode. Basically its doing more work than it needs to. I dont see why you need a join
seeing from where I sit I can see you are reading nothing off the app_cateories in the second query.
So instead of:
SELECT user_id ,apid,category_id ,projectname FROM projects JOIN app_categories ON aacid =category_id WHERE aacid=$cpid ORDER BY projectname asc
remove the joins and read off the $dpid into category_id directly like so:
SELECT user_id ,apid,category_id ,projectname FROM projects WHERE category_id =$cpid ORDER BY projectname asc
Unless one of the columns on the SELECT end belongs to app_categories.
If this is true then even in both queries it poses another problem in the result array coz it seems you are trying to use an array index that was never read.
The array index, $noticia[aacid] cannot exist based on your code so you will have a blank result based on that.
Also the first query above, if you really need to read from both tables then you have a few logic errors. Maybe the above fixes things. If not let me know and I
can go into the logic errors in your code.
---------------------------------------
Steve Obbayi: Software Developer
www.sobbayi.com
----- "Imelda Mueni" <mueni.imelda1@gmail.com> wrote:
> Hi guyz , am trying to link to tables, when a user selects one category it should bring projects only associated with the selected category
>
> am some how not able to select and link specific categories below is my code ..n ideas will be appreciated
>
>
> <?
$cpid = $_GET['id'];
//db connection is here
@$cat=$_GET['cat'];
if(strlen($cat) > 0 and !is_numeric($cat)){ // to check if $cat is numeric data or not.
echo "Data Error";
exit;
}
@$cat=$HTTP_GET_VARS['cat'];
///////// Getting the data from Mysql table for first list box category//////////
$quer2=mysql_query("SELECT DISTINCT aacid,categoryname FROM app_categories order by categoryname");
///////////// End of query for first list box////////////
/////// second drop down list we will check if category is selected else we will display all the project/////
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT user_id ,apid,category_id ,projectname FROM projects join app_categories on aacid =category_id where aacid=$cpid order by projectname asc");
}else{$quer=mysql_query("SELECT projectname FROM projects order by projectname"); }
////////// end of query for second subcategory drop down list box ///////////////////////////
/// Add your form processing page address to action in above line.////
echo "<form method=post name=f1 action='dd-check.php'>";
////////// Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['aacid']==@$cat){echo "<option selected value='$noticia2[aacid]'>$noticia2[categoryname]</option>"."<BR>";}
else{echo "<option value='$noticia2[aacid]'>$noticia2[categoryname]</option>";}
}
echo "</select>";
////////////////// This will end the first drop down list ///////////
////////// Starting of second drop downlist /////////
echo "<select name='subcat'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[aacid]'>$noticia[projectname]</option>";
}
echo "</select>";
////////////////// This will end the second drop down list ///////////
echo "<input type=submit value=Submit>";
echo "</form>";
?>
>
> this is dd-check.php
>
>
>
> <html>
>
> <head>
> <title></title>
>
> </head>
>
> <body>
> <?
> $cat=$_POST['cat'];
> $subcat=$_POST['subcat'];
>
> echo "Value of \$cat = $cat <br>Value of \$subcat = $subcat ";
>
>
> ?>
>
> </body>
>
> </html
>
> _______________________________________________
Skunkworks mailing list
Skunkworks@lists.my.co.ke
http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks
------------
Skunkworks Rules
http://my.co.ke/phpbb/viewtopic.php?f=24&t=94
------------
Other services @ http://my.co.ke