SUbcategory

Reply

Join Date: Jul 2008
Posts: 32
Reputation: knrakesh is an unknown quantity at this point 
Solved Threads: 0
knrakesh's Avatar
knrakesh knrakesh is offline Offline
Light Poster

SUbcategory

 
0
  #1
Dec 24th, 2008
Hello friends
Iam unabing to add subcategory
and iam trying to add in the same table in which the categories are there can anyone please help me in adding subcategories and categories in a same table please

Thank u
KNR
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 323
Reputation: compdoc is an unknown quantity at this point 
Solved Threads: 21
compdoc's Avatar
compdoc compdoc is offline Offline
Posting Whiz

Re: SUbcategory

 
0
  #2
Dec 24th, 2008
please post your code, so we can see what you are doing
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 32
Reputation: knrakesh is an unknown quantity at this point 
Solved Threads: 0
knrakesh's Avatar
knrakesh knrakesh is offline Offline
Light Poster

Re: SUbcategory

 
0
  #3
Dec 24th, 2008
Thanks for the reply sir
can u please check the code once and see please

  1. <?php
  2. //ob_start();
  3. //include_once('login_check.php');
  4. include_once('functions.php');
  5. if($_SERVER['REQUEST_METHOD']=='POST')
  6. {
  7. if(!isset($_GET['fid']))
  8. {
  9. $qry1="SELECT * FROM categories WHERE catname='".$_POST['cname']."'";
  10. $res1=mysql_query($qry1) or die(mysql_error());
  11. $num1=mysql_num_rows($res1);
  12. if($num1!=0)
  13. {$msg1="This Category with this name already exists "; }
  14. if($num1==0)
  15. /*{
  16. if($HTTP_POST_FILES["cimage"]["size"] >1)
  17. {
  18. $ext = substr($HTTP_POST_FILES['cimage']['name'],strpos($HTTP_POST_FILES['cimage']['name'],'.')+1);
  19. $ext_arr=array("jpeg","ping","jpg","gif","bmp");
  20. //if (in_array($ext,$ext_arr))
  21. {
  22. $prlimage=substr($HTTP_POST_FILES['cimage']['name'],0,strpos($HTTP_POST_FILES['cimage']['name'],'.'));
  23. $prlimage.=time();
  24. $prlimage.=strstr($HTTP_POST_FILES['cimage']['name'],'.');
  25. $prlimage="../uploadedimages/categories/".$prlimage;
  26. if(!move_uploaded_file($HTTP_POST_FILES['cimage']['tmp_name'],$prlimage)) { $prlimage=""; }
  27. chmod($prlimage,0777);
  28. } else
  29. {
  30. $prlimage="";
  31. }*/
  32. $qry2="INSERT INTO categories (catname,cimg,parentid,status,added_date) VALUES ('".$_POST['cname']."','".$prlimage."','".$_POST['cat_id']."','1',now())";
  33. $res2=mysql_query($qry2) or die(mysql_error());
  34. $ic_id=mysql_insert_id();
  35. header("location:addsubcat.php?msg=1");
  36. }
  37. }
  38. if(isset($_GET['fid']))
  39. {
  40.  
  41. $qry1="SELECT * FROM categories WHERE catname='".$_POST['cname']."' AND id!='".$_GET['fid']."'";
  42. $res1=mysql_query($qry1) or die(mysql_error());
  43. $num1=mysql_num_rows($res1);
  44. //if($num1==0)
  45. /*{
  46. if($HTTP_POST_FILES["cimage"]["size"] >1)
  47. {
  48.  
  49. $ext = substr($HTTP_POST_FILES['cimage']['name'],strpos($HTTP_POST_FILES['cimage']['name'],'.')+1);
  50. $ext_arr=array("jpeg","ping","jpg","gif","bmp");
  51. //if (in_array($ext,$ext_arr)) {
  52. $prlimage=substr($HTTP_POST_FILES['cimage']['name'],0,strpos($HTTP_POST_FILES['cimage']['name'],'.'));
  53. $prlimage.=time();
  54. $prlimage.=strstr($HTTP_POST_FILES['cimage']['name'],'.');
  55. $prlimage="../uploadedimages/categories/".$prlimage;
  56. if(!move_uploaded_file($HTTP_POST_FILES['cimage']['tmp_name'],$prlimage)) { $prlimage=""; }
  57. chmod($prlimage,0777);
  58. } else {
  59. $prlimage=$_POST['oldimage'];
  60. }}*/
  61.  
  62. $qry2="UPDATE `categories` SET catname='".$_POST['cname']."',cimg='".$prlimage."',parentid='".$_POST['cat_id']."' WHERE id='".$_GET['fid']."'";
  63. $res2=mysql_query($qry2) or die(mysql_error());
  64. echo '<script language="javascript">window.location.href="addsubcat.php?msg=2"</script>';
  65. //header("location:addsubcat.php?msg=2");
  66. //}
  67. }
  68.  
  69. ?>
  70. <?php
  71. if(!empty($_GET['fid']))
  72. {
  73. $qry3="SELECT * FROM categories WHERE parentid!=0 and id='".$_GET['fid']."'";
  74. $res3=mysql_query($qry3) or die(mysql_error());
  75. $row3=mysql_fetch_array($res3);
  76. $show=" Edit ";
  77. }
  78. else
  79. {
  80. $show =" Add ";
  81. }
  82. if(!empty($_GET['start'])){ $start=$_GET['start']; }
  83. else{ $start=0; }
  84. $len=10;
  85. if(!empty($_GET['start']))
  86. {
  87. $link="addsubcat.php?a=a&start=".$_GET['start']."";
  88. }else{
  89. $link="addsubcat.php?a=a";
  90. }
  91.  
  92. if(!empty($_GET['cn']))
  93. {
  94. if($_GET['cn']==1){ $con=1; $m=4; }
  95. else { $con=0; $m=5;}
  96. mysql_query(" update categories set status='".$con."' where id='".$_GET['id']."' ");
  97. header("location:addsubcat.php?msg=".$m."");
  98. }
  99. if(!empty($_GET['delid'])){
  100. $t="delete from categories WHERE id='".$_GET['delid']."'";
  101. mysql_query($t);
  102. mysql_query("delete from categories where id='".$_GET['cat_id']."'");
  103. if(!empty($_GET['start']))
  104. {
  105. header("location:addsubcat.php?msg=del&start=".$_GET['start']."");
  106. }else{
  107. header("location:addsubcat.php?msg=del");
  108. }
  109. }
  110.  
  111. $fres=mysql_query("SELECT * FROM categories where parentid!=0 ORDER BY id");
  112. $fcunt=mysql_num_rows($fres);
  113. $fres=mysql_query("SELECT * FROM categories where parentid!=0 ORDER BY id DESC LIMIT $start,$len");
  114.  
  115. $cat_arr=array();
  116. $ar_res=mysql_query("select * from categories order by id");
  117. while($ar_rw=mysql_fetch_assoc($ar_res)) {
  118. $cat_arr[$ar_rw['catname']]=$ar_rw['id'];
  119. }
  120.  
  121.  
  122.  
  123. if(!empty($_GET['fid']))
  124. {
  125. $qry3="SELECT * FROM categories WHERE id='".$_GET['fid']."'";
  126. $res3=mysql_query($qry3) or die(mysql_error());
  127. $num3=mysql_num_rows($res3);
  128. if($num3>0)
  129. {
  130. $catid=mysql_result($res3,0,'parentid');
  131.  
  132. }
  133. }
  134. ?><head>
  135. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  136. <title>..</title>
  137. <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
  138. <meta name="Powered by BitraNet Pvt.Ltd.," CONTENT="http://www.bitranet.com">
  139. <link rel="stylesheet" type="text/css" href="../site.css">
  140. <script language="javascript">
  141. function chkaddsubcat()
  142. {
  143. a=document.formaddsubcat;
  144. if(a.cat_id.value=='')
  145. {
  146. alert ("Please Select Category");
  147. a.cat_id.focus();
  148. return false;
  149. }
  150. if(a.c_name.value=='')
  151. {
  152. alert ("Please Select SubCategory");
  153. a.c_name.focus();
  154. return false;
  155. }
  156. if (a.cimage.value==""){ alert("Please Upload Logo"); a.cimage.focus(); return false;}
  157. var ftypes=['gif','jpeg','jpg','GIF','JPEG','JPG'];
  158. filename =a.cimage.value;
  159. dots = filename.split(".");
  160. ftype = dots[dots.length-1];
  161. if((ftype =="")||(ftype =="gif")||( ftype == "jpeg" )||( ftype == "jpg" )||( ftype == "GIF" )||( ftype == "JPEG" )||( ftype == "JPG" ))
  162. { }
  163. else
  164. {
  165. alert("Only upload images that end with these file types \n\n" + (ftypes));
  166. a.cimage.focus();
  167. return false;
  168. }
  169. }
  170. </script>
  171. <style type="text/css">
  172. <!--
  173. body {
  174. margin-left: 0px;
  175. margin-top: 0px;
  176. margin-right: 0px;
  177. margin-bottom: 0px;
  178. }
  179. -->
  180. </style></head>
  181. <body >
  182. <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  183. <tr>
  184. <td height="50" colspan="3" align="right"></td>
  185. </tr>
  186. <tr>
  187. <td width="17%" valign="top"><? include('left.php');?></td>
  188. <td width="1" bgcolor="#6B6B6B" ><img src="../images/spacer.gif" width="1" height="1"></td>
  189. <td width="83%" valign="top" ><table width="100%" border="0" cellspacing="0" cellpadding="1">
  190. <tr>
  191. <td colspan="2"><table width="100%" border="0" cellpadding="1" cellspacing="0">
  192. <tr>
  193. <td bgcolor="#8B8B8B"><table width="100%" border="0" cellspacing="0" cellpadding="0">
  194. <tr>
  195. <td height="20" bgcolor="#E2E2E2" class="styleforallbold">&nbsp;
  196. <?=$show ?>
  197. Sub Category</td>
  198. </tr>
  199. </table></td>
  200. </tr>
  201. </table></td>
  202. </tr>
  203. <tr>
  204. <td height="30" colspan="2" align="center" valign="middle" class="red"></td>
  205. </tr>
  206. <tr>
  207. <td colspan="2" valign="top"><form name="formaddsubcat" enctype="multipart/form-data" action="" method="post" onSubmit="return chkaddsubcat();">
  208. <table width="80%" border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#FFFFFF">
  209. <tr>
  210. <td bgcolor="#8B8B8B"><table width="100%" border="0" align="center" cellpadding="6" cellspacing="0" bgcolor="#FFFFFF" >
  211. <tr >
  212. <td colspan="3" align="right" nowrap><span class="alerts">* fields required</span></td>
  213. </tr>
  214. <tr >
  215. <td colspan="3" align="center" nowrap class="alerts"><? if(isset($msg1)) { echo $msg1;}?></td>
  216. </tr>
  217.  
  218.  
  219. <tr align="center" >
  220. <td align="right" valign="top" class="style18"><strong class="style20"><span class="star">* </span>Category </strong></td>
  221. <td valign="top" class="styleforallbold"><strong>:</strong></td>
  222. <td align="left"><label>
  223. <select name="cat_id" id="cat_id" class="box2" >
  224. <option value="" >-Select Category-</option>
  225. <?
  226. /*if(isset($_POST['cat_id'])){ $catid=$_POST['cat_id'];}
  227. else if(!empty($_GET['fid'])) $catid=$catid; else $catid='';
  228. getcategories($catid);*/
  229. if(isset($_POST['cat_id'])) { getmaincat($_POST['cat_id']); }
  230. else
  231. { getmaincat();}
  232. ?>
  233.  
  234. </select>
  235. </label></td>
  236. </tr>
  237. <tr align="center" >
  238. <td width="26%" align="right" valign="top" class="style18"><span class="h4"><strong class="star">*</strong></span><strong class="style20"><span class="red">Sub </span>Category </strong></td>
  239. <td width="3%" valign="top" class="styleforallbold"><strong>:</strong></td>
  240. <td width="71%" align="left"><label>
  241. <input type="text" name="cname" id="cname" class="box2" <? if(!empty($_GET['fid'])){?>value="<?=$row3['cname']?>"<? } ?> >
  242. </label></td>
  243. </tr>
  244. <tr align="center" >
  245. <td align="right" valign="top" class="style18"><span class="h4"><strong class="star">*</strong></span><strong>Upload Logo</strong></td>
  246. <td valign="top" class="styleforallbold"><strong>:</strong></td>
  247. <td align="left"><label>
  248. <input type="file" name="cimage" id="cimage" class="box2" />
  249. <br>
  250. <br>
  251. <? if(isset($_GET['fid'])){?>
  252. <a href="javascript:;" class="mlinks" onClick="window.open('view_cimage.php?vid=<?=$_GET['fid'];?>','','scrollbars=yes,width=500,height=500')" > View </a>
  253. <? } ?>
  254. <input type="hidden" name="oldimage" value="<?=$row3['cimg'];?>">
  255. </label></td>
  256. </tr>
  257.  
  258. <tr align="center" >
  259. <td>&nbsp;</td>
  260. <td>&nbsp;</td>
  261. <td align="left"><input type="submit" name="Submit" value="Submit"></td>
  262. </tr>
  263. <tr >
  264. <td colspan="3">&nbsp;</td>
  265. </tr>
  266. </table></td>
  267. </tr>
  268. </table>
  269. </form></td>
  270. </tr>
  271. <tr>
  272. <td colspan="2" valign="top">&nbsp;</td>
  273. </tr>
  274. <tr>
  275. <td colspan="2" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="1">
  276. <tr>
  277. <td colspan="2"><table width="100%" border="0" cellpadding="1" cellspacing="0">
  278. <tr>
  279. <td bgcolor="#8B8B8B"><table width="100%" border="0" cellspacing="0" cellpadding="0">
  280. <tr>
  281. <td height="20" bgcolor="#E2E2E2" class="styleforallbold">&nbsp;&nbsp;Manage Sub Categories </td>
  282. </tr>
  283. </table></td>
  284. </tr>
  285. </table></td>
  286. </tr>
  287. <tr>
  288. <td height="30" colspan="2" align="center" valign="middle">
  289. <span class="alerts">
  290. <?
  291. if(!empty($_GET['msg']))
  292. {
  293. switch($_GET['msg'])
  294. {
  295.  
  296. case 1: echo "Category Added successfully.";
  297. break;
  298. case 2: echo "Category Edited successfully.";
  299. break;
  300. case 3: echo "Category Deleted successfully.";
  301. break;
  302. case 4: echo "Category Activated ";
  303. break;
  304. case 5: echo "Category In-activated ";
  305. break;
  306.  
  307. default: echo "";
  308. }
  309.  
  310. }
  311. ?> </span> </td>
  312. </tr>
  313. <script language="javascript">
  314. function del(x)
  315. {
  316. if(confirm("Deletion of this record will result to delete all products based on this category!!!\n \t\t\t Are you sure you want to continue..."))
  317. {
  318. window.location="addsubcat.php?delid="+x;
  319. }
  320. return;
  321. }
  322. </script>
  323. <tr>
  324. <td colspan="2" valign="top"><table width="80%" border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#FFFFFF">
  325. <tr>
  326. <td bgcolor="#8B8B8B"><table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
  327. <tr bgcolor="#8B8B8B">
  328. <td width="25%"class="style18"><strong class="whitebold">Sub Category</strong></td>
  329. <td width="17%" class="style18"><strong class="whitebold">Category</strong></td>
  330. <td width="15%"align="center" class="style18"><strong class="whitebold">Status</strong></td>
  331. <td width="8%" align="center" class="style18"><strong class="whitebold">Edit </strong></td>
  332. <td width="19%" align="center" class="style18"><strong class="whitebold">View</strong></td>
  333. <td width="2%"align="center" class="style18"><strong class="whitebold">Delete</strong></td>
  334. </tr>
  335. <?
  336. if($fcunt>0){
  337. while($frow=mysql_fetch_assoc($fres)){
  338. $cat_res=mysql_query("SELECT catname,id FROM categories WHERE id =".$frow['parentid']);
  339. $cat_row=mysql_fetch_array($cat_res,MYSQL_BOTH);
  340. if($frow["status"]==1){$stat="Active";$up="inact";$colo="green"; }
  341. else {$stat="In-Active";$up="act";$colo="Red";}
  342. ?>
  343. <tr >
  344. <td class="style20"><?=$frow['catname'];?> </td>
  345. <td class="style20"><?=array_search($frow['parentid'],$cat_arr);?></td>
  346. <? // its for active/incative
  347. if($frow['status']==0)
  348. {
  349. $fs="In-Active";
  350. $sf=1;
  351. }
  352. else
  353. {
  354. $fs="Active";
  355. $sf=2;
  356. }
  357. ?>
  358. <td align="center" class="blinks" ><a href="addsubcat.php?act=1&id=<? echo $frow['id']?>&cn=<? echo $sf?>" class="slinks"><? echo $fs?></a> </td>
  359. <td height="22" align="center" ><a href="addsubcat.php?id=<? echo $frow['id']?>" class="slinks">Edit</a> </td>
  360. <td align="center" ><a href="javascript:;" class="slinks" onClick="window.open('viewsubcat.php?fid=<?=$frow['id'];?>','no','scrollbars=yes,width=550,height=400')" >View</a> </td>
  361. <td width="31%" height="22" align="center" ><a href="javascript:del('<? echo $frow['id'];?>')" class="slinks">Delete</a> </td>
  362. </tr>
  363. <?
  364. }
  365. }
  366. ?>
  367. <tr>
  368. <td height="22" colspan="6" align="center" class="brwnbold" ><? if($fcunt>0){ siri_drawNavigation($start,$fcunt,$link); } else { echo "<span class='brwnbold'>".'No Records Found'."</span>";}?></td>
  369. </tr>
  370. </table></td>
  371. </tr>
  372. </table></td>
  373. </tr>
  374. <tr>
  375. <td colspan="2" valign="top">&nbsp;</td>
  376. </tr>
  377. </table></td>
  378. </tr>
  379. </table></td>
  380. </tr>
  381. <tr>
  382. <td colspan="3"><img src="../images/spacer.gif" width="1" height="1"></td>
  383. </tr>
  384. <tr>
  385. <td height="1" colspan="3" align="right" bgcolor="#737373"><img src="../images/spacer.gif" width="1" height="1"></td>
  386. </tr>
  387. <tr>
  388. <td colspan="3" align="center" ></td>
  389. </tr>
  390. </table>
  391. </body>
  392. </html>
Last edited by peter_budo; Dec 29th, 2008 at 5:37 am. Reason: Keep It Organized - Please help us to keep the site organized by taking the extra minute to make sure you are posting in the correct place.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 32
Reputation: knrakesh is an unknown quantity at this point 
Solved Threads: 0
knrakesh's Avatar
knrakesh knrakesh is offline Offline
Light Poster

Re: SUbcategory

 
0
  #4
Dec 24th, 2008
and 1 more thing sir i want the category and subcategories have to be saved in the same table

please sir
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 323
Reputation: compdoc is an unknown quantity at this point 
Solved Threads: 21
compdoc's Avatar
compdoc compdoc is offline Offline
Posting Whiz

Re: SUbcategory

 
0
  #5
Dec 24th, 2008
ok I'll have to take a look at this later, but it's possible that you might be able to fix this by making a few small changes to your script. for example I suggest that you use <?php for all of your opening tags for php. one more thing is that some of your code is not wrapped in the php tags correctly. if you load this page into a sever will see what I mean. some of the code displays on the page.

also I noticed that your <label> tags are not correct they are used to label an input field like this

<label for="email">Email:</label>
<input name="email" id="email" type="text" class="formbox" />

the input tag is not placed in between the <label> tag

I will take another look at it when I get back unless someone else does it first. I'll be back on the 26'th of December.
Last edited by compdoc; Dec 24th, 2008 at 1:22 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 357
Reputation: death_oclock will become famous soon enough death_oclock will become famous soon enough 
Solved Threads: 37
death_oclock's Avatar
death_oclock death_oclock is offline Offline
Posting Whiz

Re: SUbcategory

 
0
  #6
Dec 24th, 2008
Please use CODE tags. And could you post the relevant code so we don't have to wade through all of that? Try posting just where it is getting or defining the categories/subcategories and where it is adding things to a table (in a database, I assume). But without looking at code (sorry, I'm lazy) I think you could add a field for a parent category. It would refer to the id (an id field is also needed, if you haven't already made one) of another row in the table. It could be -1 if it is a top-level catergory, to distinguish from a subcategory.
Last edited by death_oclock; Dec 24th, 2008 at 6:27 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC