Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Replicating old ASP code into PHP

Avatar of djfenom
djfenom asked on
ASPPHP
29 Comments1 Solution317 ViewsLast Modified:
I've got a script that was created in ASP and now I need to use it in PHP.

It's basically populating a navigation and sub navigation. The initial navigation is populated by a table called category and the subnav is populated by a table called subcat.

The structure is something like this:

Home
Products
     item1
     item2
     item3
     item4
Services
     serv1
     serv2
     serv3
     serv4
About
Contact

I've got it to work to an extent, but the subnav is showing on each when it should only be showing on the particular category.

I've attached 2 jpegs, the first is how the nav used to work in ASP, and the second is the PHP version.

Here is my ASP code, PHP code in code box:
<%
Dim RSnav
Dim RSnav_numRows

Set RSnav = Server.CreateObject("ADODB.Recordset")
RSnav.ActiveConnection = MM_hill_STRING
RSnav.Source = "SELECT * FROM category"
RSnav.CursorType = 0
RSnav.CursorLocation = 2
RSnav.LockType = 1
RSnav.Open()

RSnav_numRows = 0
%>

<%
Dim RSsubcat__MMColParam
RSsubcat__MMColParam = "1"
If (Request.QueryString("cat") <> "") Then
  RSsubcat__MMColParam = Request.QueryString("cat")
End If
%>
<%
Dim RSsubcat
Dim RSsubcat_numRows

Set RSsubcat = Server.CreateObject("ADODB.Recordset")
RSsubcat.ActiveConnection = MM_hill_STRING
RSsubcat.Source = "SELECT * FROM subcat WHERE category = " + Replace(RSsubcat__MMColParam, "'", "''") + ""
RSsubcat.CursorType = 0
RSsubcat.CursorLocation = 2
RSsubcat.LockType = 1
RSsubcat.Open()

RSsubcat_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
RSnav_numRows = RSnav_numRows + Repeat1__numRows
%>
<%
Dim Repeat3__numRows
Dim Repeat3__index

Repeat3__numRows = -1
Repeat3__index = 0
RSsubcat_numRows = RSsubcat_numRows + Repeat3__numRows
%>


<ul class="subnav">
        <%
While ((Repeat1__numRows <> 0) AND (NOT RSnav.EOF))
            ID = RSnav.Fields.Item("categoryID").Value
%>
            <% If ID = request.querystring("cat") + 0 Then %>
        <li class="open_nav"><%=(RSnav.Fields.Item("categoryName").Value)%>
            <% else %>
        <li><a href="products-list.asp?cat=<%=(RSnav.Fields.Item("categoryID").Value)%><% if RSnav.Fields.Item("categoryFirst").Value <> "" then %>&amp;sub=<%=RSnav.Fields.Item("categoryFirst").Value%><% end if %>"><%=(RSnav.Fields.Item("categoryName").Value)%></a>
            <% end if %>
                        <ul>
            <% If Repeat1__index = request.querystring("cat") -1 Then
            While ((Repeat3__numRows <> 0) AND (NOT RSsubcat.EOF))
            subID = RSsubcat.Fields.Item("subcatID").Value
            %>
                        <% If subID = request.querystring("sub") + 0 Then %>
                          <li><%=(RSsubcat.Fields.Item("subcatName").Value)%></li>
                        <% else %>
                          <li><a href="products-list.asp?cat=<%=request.querystring("cat")%>&amp;sub=<%=(RSsubcat.Fields.Item("subcatID").Value)%>"><%=(RSsubcat.Fields.Item("subcatName").Value)%></a></li>
                        <% end if %>
                          <%
              Repeat3__index=Repeat3__index+1
              Repeat3__numRows=Repeat3__numRows-1
              RSsubcat.MoveNext()
            Wend
            end if
            %>
            </ul>
        <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  RSnav.MoveNext()
Wend
%>
       
      </ul>

Thanks

Chris
<ul class="subnav">
      <?php do {
	  $ID = $row_RSnav['categoryID'];
	  ?>
      <?php if ($ID = $_GET['cat'] + "0") { ?>
        <li class="open_nav"><?php echo $row_RSnav['categoryName']; ?>
        <? } else { ?>
        <li><a href="products-list.php?cat=<?php echo $row_RSnav['categoryID']; ?><?php if ($row_RSnav['categoryFirst'] != "") { ?>&amp;sub=<?php echo $row_RSnav['categoryFirst']; ?><?php } ?>"><?php echo $row_RSnav['categoryName']; ?></a>
        <?php } ?>
          <ul>
            <?php do {
			$subID = $row_RSsubcat['subcatID'];
			?>
      		<?php if ($subID = $_GET['sub'] + "0") { ?>
            <li><a href="#"><?php echo $row_RSsubcat['subcatName']; ?></a></li>
        	<? } else { ?>
			<li><a href="products-list.php?cat=<?php echo $_GET['cat']; ?>&amp;sub=<?php echo $row_RSsubcat['subcatID']; ?>"><?php echo $row_RSsubcat['subcatName']; ?></a></li>
        	<?php } ?>
            <?php } while ($row_RSsubcat = mysql_fetch_assoc($RSsubcat)); ?>
          </ul>
        </li>
        <?php } while ($row_RSnav = mysql_fetch_assoc($RSnav)); ?>
    </ul>
images.zip
ASKER CERTIFIED SOLUTION
Avatar of Ionut A. Tudor
Ionut A. TudorFlag of Romania imagePHP Programmer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 29 Comments.
See Answers