Page 1 of 1

Need A Volunteer to help me

Posted: Mon Sep 17, 2007 1:22 pm
by stephanny07
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello...

I'm new to PHP and have this page written in ASP.....I need to translate it to PHP...can anyone help me ...please..

Thank you..

[syntax="asp"]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<%
Dim conn, connstr

'create an instance of the ADO connection and recordset objects
set conn = Server.CreateObject("ADODB.Connection")

'define the connection string, specify database driver
connstr = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=_database; User=_admin;Password=admin;Option=3;"

'Open the connection to the database
conn.Open(connstr)
	
	select case request.QueryString("sort")
		case "lastname"
			sortby = "last_name, first_name"
		case "firstname"
			sortby = "first_name, last_name"
		case "emp"
			sortby = "employer"
		case "ind1"
			sortby = "industry_1"
		case "functional"
			sortby = "functional"
		case "position"
			sortby = "position_level"
		case else
			sortby = "last_name, first_name"
	end select

	sql = "SELECT * FROM Active ORDER BY LAST_NAME, FIRST_NAME"
	set namers = conn.Execute(sql)

	if session("searchcriteria") <> "" then
		sql = "SELECT * FROM Active " & session("searchcriteria") & " ORDER BY " & sortby
	else
		sql = "SELECT * FROM Active ORDER BY " & sortby
	end if
	set rs = conn.Execute(sql)

	sql = "SELECT distinct position_level FROM Active WHERE position_level <> '' "
	set positionrs = conn.Execute(sql)


	sql = "SELECT distinct functional FROM Active WHERE functional <> '' "
	set trainrs = conn.Execute(sql)
	
	sql = "SELECT distinct industry_1 FROM Active WHERE industry_1 <> '' "
	set orgrs = conn.Execute(sql)
	
	sql = "SELECT distinct employer FROM Active WHERE employer <> '' "
	set employrs = conn.Execute(sql)
	
	sql = "SELECT distinct project FROM Active WHERE project <> '' "
	set projrs = conn.Execute(sql)

%>

<body>
<div align="center">
<h1><strong>Records</strong></h1>
</div>
<form action="search3.asp" method="post">
<table width="100%" border="0">

  <tr>
      <td><strong>SEARCH BY </strong>: Position:
	    <select name="positionsearch">
	  <option></option>
	  <%while not positionrs.EOF%>
		<option value="<%=positionrs("position_level")%>"><%=positionrs("position_level")%></option>
	  <%positionrs.MoveNext%>
	  <%wend%>
	  </select>
Project:	    
<select name="projectsearch">
	  <option></option>
	  <%while not projrs.EOF%>
		<option value="<%=projrs("project")%>"><%=projrs("project")%></option>
	  <%projrs.MoveNext%>
	  <%wend%>
	  </select>
      
        Function: 
	     <select name="trainsearch">
	  <option value=""></option>
	  <%while not trainrs.EOF%>
		<option value="<%=trainrs("functional")%>"><%=trainrs("functional")%></option>
	  <%trainrs.MoveNext%>
	  <%wend%>
	  </select>
        Industry:
        <select name="dirsearch">
	  <option></option>
	  <%while not orgrs.EOF%>
		<option value="<%=orgrs("industry_1")%>"><%=orgrs("industry_1")%></option>
	  <%orgrs.MoveNext%>
	  <%wend%>
	  </select>
      Employer:
        <select name="empsearch">
	  <option></option>
	  <%while not employrs.EOF%>
		<option value="<%=employrs("employer")%>"><%=employrs("employer")%></option>
	  <%employrs.MoveNext%>
	  <%wend%>
	  </select>
        <input type="submit" name="submit" value="Search"></td>
  </tr>
  <tr>
      <td><strong>OR</strong>:&nbsp; 
        <input type="submit" name="submit" value="View All"></td>
  </tr>
</table>
</form>
<div align="right"><font size="-1"><a href="menu.htm">Back to Menu</a></font></div>
<table width="100%" border="1">
	<% if session("searchresults") <> "" then %>
		<tr><td colspan="9"><strong>Search Criteria: </strong><font color=red><%=session("searchresults")%></font></td></tr>
	<% end if %>	

  <tr> 
    <td width="17%" valign="bottom" bgcolor="#999999"><strong><a href="view_records.asp?sort=lastname">Last 
      Name</a></strong></td>
    <td width="19%" valign="bottom" bgcolor="#999999"><strong><a href="view_records.asp?sort=firstname">First 
      Name</a></strong></td>
	 <td width="7%" valign="bottom" bgcolor="#999999"><strong>City </strong></td>
    <td width="14%" valign="bottom" bgcolor="#999999"><p><strong><a href="view_records.asp?sort=emp">Employer</a>
	</strong></p></td>
    <td width="12%" valign="bottom" bgcolor="#999999"><strong><a href="view_records.asp?sort=ind1">Industry</a>
	</strong></td>
	 <td width="15%" valign="bottom" bgcolor="#999999"><strong><a href="view_records.asp?sort=functional">Function</a></strong></td>
	 <td width="16%" valign="bottom" bgcolor="#999999"><strong><a href="view_records.asp?sort=position">Position Level</a></strong></td>
  </tr>
  <% WHILE NOT rs.EOF %>
  
  <tr>
    <td height="30"><a href="view_info.asp?id=<%=rs("id")%>">
      <p><%=UCase(rs("last_name"))%>&nbsp;<br>
      <a href="editAssociate.asp?id=<%=rs("id")%>">Edit Info for <%=UCase(rs("last_name"))%> </p>
    </td>
	<td><%=UCase(rs("first_name"))%>&nbsp;</td>
	<td><%=rs("city_location")%>&nbsp;</td>
	<td><%=rs("employer")%>&nbsp;</td>
	<td><%=rs("industry_1")%>&nbsp;</td>
	<td><%=rs("functional")%>&nbsp;</td>
	<td><%=rs("position_level")%>&nbsp;</td>
  </tr>
  <% rs.Movenext %>
  <% wend %>
</table>
</body>
</html>

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Sep 17, 2007 1:36 pm
by feyd
Where's the difficulty in translating it yourself?

Posted: Mon Sep 17, 2007 1:45 pm
by stephanny07
I'm not sure how to do the sort by, sessions, selects, while loops...i tried it and it was wrong...please help. Thank you so much.

Posted: Mon Sep 17, 2007 2:05 pm
by feyd
What did you try?

Posted: Mon Sep 17, 2007 2:09 pm
by stephanny07
this is what i had... does not work

Code: Select all

<?php
 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<?
//dim $conn, $connstr;
 
//create an instance of the ADO connection and recordset objects
set $conn = Server.CreateObject("ADODB.Connection");
 
//define the connection string, specify database driver
$connstr = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=_database; User=_admin;Password=1admin;Option=3;";
 
//Open the connection to the database
$conn.$Open[$connstr];
	
	select case @$_GET["sort"];
		case "lastname";
			$sortby = "last_name, first_name";
		case "firstname";
			$sortby = "first_name, last_name";
		case "emp";
			$sortby = "employer";
		case "ind1";
			$sortby = "industry_1";
		case "functional";
			$sortby = "functional";
		case "position";
			$sortby = "position_level";
		case } else {
			$sortby = "last_name, first_name";
	end select;
 
	$sql = "SELECT * FROM Active ORDER BY LAST_NAME, FIRST_NAME";
	set $namers = $conn.Execute($sql);
 
	if (session("searchcriteria") != "") {
		$sql = "SELECT * FROM Active ".session("searchcriteria")." ORDER BY ".$sortby;
	} else {
		$sql = "SELECT * FROM Active ORDER BY ".$sortby;
	}
	set $rs = $conn.Execute($sql);
 
	$sql = "SELECT distinct position_level FROM Active WHERE position_level <> '' ";
	set $positionrs = $conn.Execute($sql);
 
 
	$sql = "SELECT distinct functional FROM Active WHERE functional <> '' ";
	set $trainrs = $conn.Execute($sql);
	
	$sql = "SELECT distinct industry_1 FROM Active WHERE industry_1 <> '' ";
	set $orgrs = $conn.Execute($sql);
	
	$sql = "SELECT distinct employer FROM Active WHERE employer <> '' ";
	set $employrs = $conn.Execute($sql);
	
	$sql = "SELECT distinct project FROM Active WHERE project <> '' ";
	set $projrs = $conn.Execute($sql);
 
?>

<body>
<div align="center">
<h1><strong>Records</strong></h1>
</div>
<form action="search3.asp" method="post">
<table width="100%" border="0">

  <tr>
      <td><strong>SEARCH BY </strong>: Position:
	    <select name="positionsearch">
	  <option></option>
	  <?while not $positionrs.$EOF?>
		<option value="<?=$positionrs["position_level"]?>"><?=$positionrs["position_level"]?></option>
	  <?$positionrs.$MoveNext?>
	  <?}?>
	  </select>
Project:	    
<select name="projectsearch">
	  <option></option>
	  <?while not $projrs.$EOF?>
		<option value="<?=$projrs["project"]?>"><?=$projrs["project"]?></option>
	  <?$projrs.$MoveNext?>
	  <?}?>
	  </select>
      
        Function: 
	     <select name="trainsearch">
	  <option value=""></option>
	  <?while not $trainrs.$EOF?>
		<option value="<?=$trainrs["functional"]?>"><?=$trainrs["functional"]?></option>
	  <?$trainrs.$MoveNext?>
	  <?}?>
	  </select>
        Industry:
        <select name="dirsearch">
	  <option></option>
	  <?while not $orgrs.$EOF?>
		<option value="<?=$orgrs["industry_1"]?>"><?=$orgrs["industry_1"]?></option>
	  <?$orgrs.$MoveNext?>
	  <?}?>
	  </select>
      Employer:
        <select name="empsearch">
	  <option></option>
	  <?while not $employrs.$EOF?>
		<option value="<?=$employrs["employer"]?>"><?=$employrs["employer"]?></option>
	  <?$employrs.$MoveNext?>
	  <?}?>
	  </select>
        <input type="submit" name="submit" value="Search"></td>
  </tr>
  <tr>
      <td><strong>OR</strong>:&nbsp; 
        <input type="submit" name="submit" value="View All"></td>
  </tr>
</table>
</form>
<div align="right"><font size="-1"><a href="menu.htm">Back to Menu</a></font></div>
<table width="100%" border="1">
	<? if (session("searchresults") != "") {?>
		<tr><td colspan="9"><strong>Search Criteria: </strong><font color=red><?=session("searchresults")?></font></td></tr>
	<? } ?>	

  <tr> 
    <td width="17%" valign="bottom" bgcolor="#999999"><strong><a href="view_records.asp?sort=lastname">Last 
      Name</a></strong></td>
    <td width="19%" valign="bottom" bgcolor="#999999"><strong><a href="view_records.asp?sort=firstname">First 
      Name</a></strong></td>
	 <td width="7%" valign="bottom" bgcolor="#999999"><strong>City </strong></td>
    <td width="14%" valign="bottom" bgcolor="#999999"><p><strong><a href="view_records.asp?sort=emp">Employer</a>
	</strong></p></td>
    <td width="12%" valign="bottom" bgcolor="#999999"><strong><a href="view_records.asp?sort=ind1">Industry</a>
	</strong></td>
	 <td width="15%" valign="bottom" bgcolor="#999999"><strong><a href="view_records.asp?sort=functional">Function</a></strong></td>
	 <td width="16%" valign="bottom" bgcolor="#999999"><strong><a href="view_records.asp?sort=position">Position Level</a></strong></td>
  </tr>
  <? WHILE NOT $rs.$EOF ?>
  
  <tr>
    <td height="30"><a href="view_info.asp?id=<?=$rs["id"]?>">
      <p><?=strtoupper($rs["last_name"])?>&nbsp;<br>
      <a href="editAssociate.asp?id=<?=$rs["id"]?>">Edit Info for <?=strtoupper($rs["last_name"])?> </p>
    </td>
	<td><?=strtoupper($rs["first_name"])?>&nbsp;</td>
	<td><?=$rs["city_location"]?>&nbsp;</td>
	<td><?=$rs["employer"]?>&nbsp;</td>
	<td><?=$rs["industry_1"]?>&nbsp;</td>
	<td><?=$rs["functional"]?>&nbsp;</td>
	<td><?=$rs["position_level"]?>&nbsp;</td>
  </tr>
  <? $rs.$Movenext ?>
  <? } ?>
</table>
</body>
</html>
I apologize ...but I"m new to this...I was trying my best

Posted: Mon Sep 17, 2007 2:18 pm
by feyd
  • PHP doesn't need to use ODBC to connect to MySQL typically. That's what mysql_connect() and its sibling functions are for.
  • "set" isn't needed, nor is even a command in PHP.
  • "select" would be a switch.
  • session(...) will convert to $_SESSION. Make sure to call session_start() at the beginning of the script.
  • Your while loops need some tuning... http://php.net/while
  • You should switch all "<?" to "<?php" and "<?=" to "<?php echo"

Posted: Mon Sep 17, 2007 2:31 pm
by stephanny07
can you help me with the switch statement? I'm going to do this piece by piece but Kinda need guidance/assistance from an expert like you

Code: Select all

switch
		 case $_GET["sort"; 
                case "lastname"; 
                        $sortby = "last_name, first_name"; 
                case "firstname"; 
                        $sortby = "first_name, last_name"; 
                case "emp"; 
                        $sortby = "employer"; 
                case "ind1"; 
                        $sortby = "industry_1"; 
                case "functional"; 
                        $sortby = "functional"; 
                case "position"; 
                        $sortby = "position_level"; 
                case } else { 
                        $sortby = "last_name, first_name"; 
        end select;

Posted: Mon Sep 17, 2007 2:37 pm
by feyd
Compare the code you have in ASP to the example code provided on the switch page I linked to already.

Posted: Mon Sep 17, 2007 2:47 pm
by stephanny07
Hey...first of all thanks for taking time to help me out.

here is what i have now....

Code: Select all

switch
		 case ($_GET sort)
		  {
                case lastname: 
                        $sortby = "last_name, first_name"; 
                case firstname: 
                        $sortby = "first_name, last_name"; 
                case emp: 
                        $sortby = "employer"; 
                case ind1 
                        $sortby = "industry_1"; 
                case functional: 
                        $sortby = "functional"; 
                case position:
                        $sortby = "position_level"; 
                case 
				} 
				else 
				{ 
                        $sortby = "last_name, first_name"; 
		}
I get this error message:

Parse error: parse error, unexpected T_CASE, expecting '(' in C:\Accounts\wwwRoot\base\admin_records.php on line 17

Posted: Mon Sep 17, 2007 3:02 pm
by califdon
stephanny07 wrote:I get this error message:

Parse error: parse error, unexpected T_CASE, expecting '(' in C:\Accounts\wwwRoot\base\admin_records.php on line 17
Go to line 17 of your script. The error message is telling you that where it was expecting a parenthesis, it found a CASE statement instead. Your CASE syntax is wrong. Reference http://us3.php.net/switch

Beyond that, before you use a $_GET array value, you should assign it to a variable, then use the variable in your CASE statement, like:

Code: Select all

...
$sort = $_GET['sort'];
...
switch ($sort) {
  case 'lastname':
...

Posted: Mon Sep 17, 2007 3:07 pm
by s.dot
It will go like this:

Code: Select all

switch($_GET['sort'])
{
    case 'casename':
    //code here
    break;

    case 'casename2':
    //code here
    break;
}

Posted: Tue Sep 18, 2007 8:29 am
by stephanny07
Can someone please help me get this WHile Loop PHP syntax correct? I'm looking on line for examples but I'm confused. Please help me. Thanks.

Code: Select all

<table width="100%" border="0"> 

  <tr> 
      <td><strong>SEARCH BY </strong>: Position: 
            <select name="positionsearch"> 
          <option></option> 
          <?while not $positionrs.$EOF?> 
                <option value="<?=$positionrs["position_level"]?>"><?=$positionrs["position_level"]?></option> 
          <?$positionrs.$MoveNext?> 
          <?}?> 
          </select> 
Project:             
<select name="projectsearch"> 
          <option></option> 
          <?while not $projrs.$EOF?> 
                <option value="<?=$projrs["project"]?>"><?=$projrs["project"]?></option> 
          <?$projrs.$MoveNext?> 
          <?}?> 
          </select> 
      
        Function: 
             <select name="trainsearch"> 
          <option value=""></option> 
          <?while not $trainrs.$EOF?> 
                <option value="<?=$trainrs["functional"]?>"><?=$trainrs["functional"]?></option> 
          <?$trainrs.$MoveNext?> 
          <?}?> 
          </select> 
        Industry: 
        <select name="dirsearch"> 
          <option></option> 
          <?while not $orgrs.$EOF?> 
                <option value="<?=$orgrs["industry_1"]?>"><?=$orgrs["industry_1"]?></option> 
          <?$orgrs.$MoveNext?> 
          <?}?> 
          </select> 
      Employer: 
        <select name="empsearch"> 
          <option></option> 
          <?while not $employrs.$EOF?> 
                <option value="<?=$employrs["employer"]?>"><?=$employrs["employer"]?></option> 
          <?$employrs.$MoveNext?> 
          <?}?> 
          </select> 
        <input type="submit" name="submit" value="Search"></td> 
  </tr> 
  <tr> 
      <td><strong>OR</strong>:&nbsp; 
        <input type="submit" name="submit" value="View All"></td> 
  </tr> 
</table>

Posted: Tue Sep 18, 2007 8:30 am
by stephanny07
Thank you to everyone that has helped me. Thanks so much.

Frances