Round Posted November 2, 2006 Share Posted November 2, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/25945-asp-to-php/ Share on other sites More sharing options...
Daniel0 Posted November 3, 2006 Share Posted November 3, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/25945-asp-to-php/#findComment-118981 Share on other sites More sharing options...
Round Posted November 3, 2006 Author Share Posted November 3, 2006 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 clearlyMany ThanksP.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. Quote Link to comment https://forums.phpfreaks.com/topic/25945-asp-to-php/#findComment-119021 Share on other sites More sharing options...
Round Posted November 3, 2006 Author Share Posted November 3, 2006 Right I have cracked it whilst loosing my hair ;DHeres 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] Quote Link to comment https://forums.phpfreaks.com/topic/25945-asp-to-php/#findComment-119157 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.