Jump to content

innopar

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Everything posted by innopar

  1. Alright update... again $query = "SELECT * FROM cat AS c LEFT JOIN subcat as cl ON cl.pid = c.id"; $result = mysql_query($query); $currentCatID = false; while($row = mysql_fetch_assoc($result)) { if($currentCatID != $row['id']) { $currentCatID = $row['pid']; $output .= "<li class=\"level0 nav-2 parent\" onmouseover=\"toggleMenu(this,1)\" onmouseout=\"toggleMenu(this,0)\"> <a href=\"product.php?cat={$row['cat_id']}\"> <span>{$row['name']}</span> </a>\n"; } $output .= "<ul class=\"level0\"> <li class=\"level1 nav-2-1 first\"> <a href=\"product.php?cat=$cat_id&subid={$row['id']}\"> <span>{$row['title']}</span> </a> </li> </ul> </li>"; } I found out that using the same variable in two tables made things ugly. So I changed the name in the 'subcat' table from 'name' to 'title' to be different from the 'cat' table. Now the code runs and it does each individual list and sublist for each sub category. I don't want that. I want one parent cat and then the sub cats to fall directly under it for a nice menu. What am I doing wrong??
  2. ah ... $query = "SELECT cat.id as cat_id, cat.name as cat_name, subcat.id as subcat_id, subcat.pid as subcat_pid, subcat.name as subcat_name FROM cat LEFT JOIN subcat ON subcat.pid = cat.id"; $result = mysql_query($query); $currentCatID = false; while($row = mysql_fetch_assoc($result)) { if($currentCatID != $row['cat_id']) { $currentCatID = $row['cat_id']; $output .= "<li class=\"level0 nav-2 parent\" onmouseover=\"toggleMenu(this,1)\" onmouseout=\"toggleMenu(this,0)\"> <a href=\"product.php?cat={$row['cat_id']}\"> <span>{$row['name']}</span> </a>\n"; } $output .= "<ul class=\"level0\"> <li class=\"level1 nav-2-1 first\"> <a href=\"product.php?cat=$catid&subid={$row['subcat_id']}\"> <span>{$row['subcat_name']}</span> </a> </li> </ul> </li>"; } Now it's doing the parent category in the top output and the bottom but no error?
  3. Interesting, I've never seen code in php like that before I don't know how to manipulate it work for my needs. I just tried to copy and past and its a no go Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
  4. Good Evening - I am in the process of trying to call back a list of categories and sub categories using a WHILE LOOP inside of a WHILE LOOP. It works on a different part of the site within the admin panel but not here. Here it only calls one sub category and moves on to the next parent category instead of finishing the loop and pulling all sub categories out... // CATEGORIES $query = "SELECT * FROM cat"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $catid = $row['id']; $catname = $row['name']; $output .= "<li class=\"level0 nav-2 parent\" onmouseover=\"toggleMenu(this,1)\" onmouseout=\"toggleMenu(this,0)\"> <a href=\"product.php?cat=$catid\"> <span>$catname</span> </a>\n"; $querynav = "SELECT * FROM subcat WHERE pid = '$catid'"; $resultnav = mysql_query($querynav); while($array = mysql_fetch_array($resultnav, MYSQL_ASSOC)) { $subcatid = $row['id']; $subcatname = $row['name']; $output .= "<ul class=\"level0\"> <li class=\"level1 nav-2-1 first\"> <a href=\"product.php?cat=$catid&subid=$subcatid\"> <span>$subcatname</span> </a> </li> </ul> </li>"; } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.