
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*

First you dont need the line *@$cat=$HTTP_GET_VARS['cat']* Secondly, in join queries you need to define the tables.tablecolumn and not just tablecolumn. Third, you haven't used this $cat variable in your sql statements anywhere. As an example of the second and third points: */////// 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 app_categories.user_id ,app_categories.apid,app_categories.category_id ,projects.projectname FROM projects join app_categories on projects.aacid =app_categories.category_id where projects.aacid=$cpid and app_categories.cat_id = $cat order by projectname asc"); * Please notice that I don't know your project therefore many of the variables in that SQL statement may need to be corrected. Otherwise that is a general sql join statement format. On Sun, May 8, 2011 at 2:09 PM, 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
-- www.golavish.com - The travel and leisure www.raccuddasys.com - code Development issues

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

it might also be easier to read through code , debug, maintain etc if you stick to separation of presentation and logic. i.e In the future, consider not having to do these echoes of HTML content from php logic : * * *echo "<form method=post name=f1 action='dd-check.php'>";* * * It is not a very scalable practice. But if it sorts out a small problem quickly for you, then by all means :-) On 8 May 2011 15:50, Steve Obbayi <steve@sobbayi.com> wrote:
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
_______________________________________________ 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
participants (4)
-
Frankline Chitwa
-
Imelda Mueni
-
Ndungi Kyalo
-
Steve Obbayi