Jump to content

ASP to PHP??


Round

Recommended Posts

How do I replicate the following piece of asp code to php?

<p><a href="progreview_disp.asp?student_id=<%=request.querystring("student_id")%>&moodlestu_id=<%=request.querystring("moodlestu_id")%>&id=<%=rs3("id")%>&review_id=<%=rs3("review_id")%>">
  <% response.write("PR No: " & rs3("review_id") & " - " & rs3("review_title") & " (" & rs3("review_date") & ")")%>
  </a></p>

Heres what I have so far:-

<a href=\"my_single_prog_review.php\">PR No: ".$row["review_id"]." ".$row["review_title"]." ".$row["review_date"]."</a>

A link is being created with each record the array finds, and being named a portion of the record. But I want the link once clicked take you to the my_single_prog_review.php page and display all the details from that specific record.

Any Ideas?

Many Thanks
Link to comment
Share on other sites

I'm not quite sure what the ASP code do, but I think I have an idea of it.

To retrieve database information do something like this: [code]<?php
$link = mysql_connect("server","username","password");
mysql_select_db("the_db");

$result = mysql_query("SELECT * FROM some_table");
while($row = mysql_fetch_assoc($result))
{
echo "<a href='my_single_prog_review.php'>PR No: {$row['review_id']} {$row['review_title']} {$row['review_date']}";
}
?>[/code]
Link to comment
Share on other sites

Ive got all the db connection and query further up in the code and is all working fine.

What the asp code is doing is, it is retrieving records from a table and displaying them as a link to another page(so what u will end up with is 'x' amount of links, all of which are named individually dependant on what records exist in the db, to give them a decription of what record they are going to link you to.) That part I can do.

What the asp code also is doing is sending a variable specific to the link record, to another page so that the linked page only displays the corresponding record. This is so that these variables be sent can be used in another query on the next page and they are specific to the record requested. It is this part I am having trouble with.

link to page progreview_disp.asp take variables [color=red]id[/color] and [color=blue]review_id[/color]
[b]<p><a href="progreview_disp.asp?stu_id=<%=request.querystring("stu_id")%>&pass_id=<%=request.querystring("pass_id")%>&id=<%=rs3("[color=red]id[/color]")%>&review_id=<%=rs3("[color=blue]review_id[/color]")%>">[/b]

Link being named with record specifics
  [b]<% response.write("PR No: " & rs3("review_id") & " - " & rs3("review_title") & " (" & rs3("review_date") & ")")%>[/b][/a]</p>

The stu_id=<%=request.querystring("stu_id")%>&pass_id=<%=request.querystring("pass_id")%> is similar to using cookies which I have done, so this part is not an issue because I can just call the cookies carrying these two variables on any page when they are required.

I cannot put id and review_id into cookies this page may return a 1000 records each with a link being created, meaning each id and review_id would have to have a cookie created.

I hope I have explained it clearly

Many Thanks

P.S just incase here is all the asp code followed by the php

[code]<%


stuid=Request.querystring("stu_id")

passid=Request.querystring("pass_id")


set con=Server.CreateObject("ADODB.Connection")
con.open "PROVIDER=SQLOLEDB;DATA SOURCE=server;UID=dbusername;PWD=dbpassword;DATABASE=dbname "

set rs3=Server.CreateObject("ADODB.recordset")
SQL3 = "SELECT * from ProgReview where stu_ID='" & stuid & "' order by review_id"
rs3.Open SQL3, Con,3,3

%>
<%if rs3.eof or rs3.bof then %>
  <p>You have no existing Progress Reviews</p>
  <% else %>
<% do until rs3.EOF%>
  <p><a href="progreview_disp.asp?stu_id=<%=request.querystring("stu_id")%>&pass_id=<%=request.querystring("pass_id")%>&id=<%=rs3("id")%>&review_id=<%=rs3("review_id")%>">
  <% response.write("PR No: " & rs3("review_id") & " - " & rs3("review_title") & " (" & rs3("review_dt") & ")")%>
  </a></p>
</p>
<%
rs3.movenext
loop
end if %>
<hr>

<p><a href="progreview.asp?stu_id=<%=request.querystring("stu_id")%>&pass_id=<%=request.querystring("pass_id")%>">Start new progress review</a>[/code]


[code]
<?php #call for cookies
$auth = $_COOKIE['auth'];
$stu_id = $_COOKIE['stu_id'];
$pass_id = $_COOKIE['pass_id'];
header("Cache-Control:no-cache");
if(!$auth == "ok")
{ header("Location:http://index.php");
exit();
}
 
  #connect to db
$conn = @mysql_connect(  "server", "dbusername", "dbpassword" )
      or die( "Err:conn");
#select db
$rs = @mysql_select_db( "dbname", $conn)
or die( "ERR:Db");

#create query
$sql = "select * from ProgReview where stu_id=\"$stu_id\" order by review_id";

#exe query
$rs = mysql_query( $sql, $conn )
or die( "Could not execute query.");

#search for matches
$num = mysql_numrows ($rs);
if ($num !=0)
{
$list = "<table border=\"0\" cellpadding=\"2\" width=\"100%\">";
$list .= "<tr>";
$list .= "<th class=table>Current Progress Reviews</th>";
$list .= "</tr>";

#retrieve data
while ( $row = mysql_fetch_array( $rs ) )
{
$list .= "<tr><td class=table><br><a href=\"my_single_prog_review.php\">PR No: " .$row["review_id"]." ".$row["review_title"]." ".$row["review_dt"]."</a></td></tr>";
}
$list .= "</table>";

#list details
echo( $list );
}
else
{ echo ("<br><center>You have no existing Progress Reviews</center>");
exit();}

?>[/code]

P.P.S I didnt write the asp code and the site its running has many problems so I'm re-writing in php. my_single_prog_review.php will be the page that displays the individual progress reviews which have been selected to be viewed.
Link to comment
Share on other sites

Right I have cracked it whilst loosing my hair ;D

Heres the code just incase it can be improved on or if it is of any use to someone.

[code]<?php
 
  #connect to db
$conn = @mysql_connect(  "localhost", "dbusername", "dbpassword" )
      or die( "Err:conn");
#select db
$rs = @mysql_select_db( "dbname", $conn)
or die( "ERR:Db");

#create query
$sql = "select * from ProgReview where stu_id=\"$stu_id\" order by review_id";

#exe query
$rs = mysql_query( $sql, $conn )
or die( "Could not execute query.");

#search for matches
$num = mysql_numrows ($rs);
if ($num !=0)
{
$list = "<table border=\"0\" cellpadding=\"2\" width=\"100%\">";
$list .= "<tr>";
$list .= "<th class=table>Current Progress Reviews</th>";
$list .= "</tr>";

#retrieve data
while ( $row = mysql_fetch_array( $rs ) )
{
$list .= "<tr><td class=table><br><form action=\"my_single_prog_review.php\" method=\"post\">PR No: " .$row["review_id"]." ".$row["review_title"]." ".$row["review_dt"]."<input type=\"hidden\" name=\"id\" value=\"".$row["id"]."\"><input type=\"hidden\" name=\"review_id\" value=\"".$row["review_id"]."\"><br><br><input type=\"submit\" value=\"View\"></form></td></tr>";
}
$list .= "</table>";

#list details
echo( $list );
}
else
{ echo ("<br><center>You have no existing Progress Reviews</center>");
exit();}

?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.