CountryGirl Posted March 30, 2010 Share Posted March 30, 2010 Hi all, I am trying to make a link from a PHP search result. To see what I'm trying to do, you can go to this page that I'm working on - www.wagonerassessor.com/searchjoin2.php. You can search by "730000450." I want to link the account number on the results to another results page that has more detailed information about that specific account. I want to link it to this page that'll have specified results on it, www.wagonerassessor.com/formresults.html. How do I create a link in PHP search results? Thank you! Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 30, 2010 Share Posted March 30, 2010 Basically, you need to create a link along with the ID of the result.. LIke so <a href="formresults.php?id=<?php echo ID_OF_RESULT;?>">Your number</a> On page searchjoin_more.php, your query will be similar to below <?php $id = isset($_GET['id']) ? $_GET['id'] : ''; $sql = "SELECT * FROM yourtable WHERE id = '".mysql_real_escape_string($id)."'"; ?> The page should be in .php , not html ! Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted March 30, 2010 Share Posted March 30, 2010 when you print echo....whatever... the result into the table. Instead of doing something like this... echo '<td>My table data</td>'; do something like this.... echo'<td><a href="www.whereever.com/results">My table data</a></td>'; Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 30, 2010 Share Posted March 30, 2010 Countrygirl is trying to get specific result based on the current result. I believe she should query it by the ID of the current result to fetch all the data! Can you post your code? Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted March 30, 2010 Share Posted March 30, 2010 Countrygirl is trying to get specific result based on the current result. I believe she should query it by the ID of the current result to fetch all the data! Can you post your code? Good point, then what she'll want to do is have the link, link to another script that passes a variable... that queries her db via the results of the account number. Something in the lines of <td><a href="more_info.php?acc_num=00034040">00034040</a></td> and someplace within the more_info.php script have this: $acount_number = $_REQUEST['acc_num']; then use that to query the db for the rest of the detailed info. Or use sessions / cookies to do it as well if prefered. But above is more along the "active link" she is looking for I think. And I missed Ik posts earlier sorry if that repeats him btw... Quote Link to comment Share on other sites More sharing options...
CountryGirl Posted March 31, 2010 Author Share Posted March 31, 2010 Thanks! Here's my code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> [code=php:0]<?php $dbHost = $dbUser = $dbPass = $dbDatabase = $search = $_POST['search']; if ($search) // perform search only if a string was entered. { $con = mysql_connect($dbHost, $dbUser, $dbPass) or die("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or die("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); $query = "SELECT Appr_Value.Account, Asmnt_Parcel.OwnersName, Asmnt_Situs.Situs FROM Appr_Value INNER JOIN Asmnt_Parcel ON Appr_Value.Account=Asmnt_Parcel.Account INNER JOIN Asmnt_Situs ON Appr_Value.Account=Asmnt_Situs.Account WHERE Appr_Value.Account LIKE '{$search}' ORDER BY Appr_Value.Account ASC"; $result = mysql_query($query, $con) or die(mysql_error().": $query"); if ($result) { echo "Results:<br><br>"; echo "<table width=90% align=center border=1><tr> <td align=center bgcolor=#4A6B3F>Account</td> <td align=center bgcolor=#4A6B3F>Owners Name</td> <td align=center bgcolor=#4A6B3F>Situs</td> </tr>"; while ($r = mysql_fetch_array($result)) { // Begin while $act = $r["Account"]; $name = $r["OwnersName"]; $situs = $r["Situs"]; echo "<tr> <td>$act</td> <td>$name</td> <td>$situs</td> </tr>"; } // end while echo "</table>"; } else { echo "Sorry, please try your search again."; } } else { echo "Start your search"; } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title>Searching Another Test</title> </head> <body bgcolor="#bba86d"> <div align="center"> </div> <h1></h1> <h1></h1> <h1>Search Records</h1> <form method="post" action="searchjoin2.php"> <table width=90% align=center> <tr><td>Search:</td><td><input type=text name='search' size=60 maxlength=255></td></tr> <td></td> <td><input type=submit value="Search Records"></td> </tr> </table> </form> <p></p> <p></p> </body> </html>[/code] If there's anymore you could add that'll help with my code, that'd be great. I think I get the general idea of what I need to do, but if there's anything you can be more specific about with seeing my code, that'd be great. I'm quite new to PHP, so, thanks for any and all help! Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 31, 2010 Share Posted March 31, 2010 In your select statement, you need to select and ID as well, that's what you need. How is your table set up? Quote Link to comment Share on other sites More sharing options...
CountryGirl Posted March 31, 2010 Author Share Posted March 31, 2010 In your select statement, you need to select and ID as well, that's what you need. How is your table set up? Okay, I was wondering that. I have an ID (an Appr_ID) that relates most of the tables together, but then some of the tables are related together by an Account number. Because not all the tables have an Appr_ID. The Appr_ID is my primary key (on the Appr_Value table). There is one table that has Appr_ID & Account and that table (my base one in the code - Appr_Value) is what links the Appr_ID to the account numbers. Which is why I was linking some of it by Account, but I could switch some of the coding to have it link by the ID number. Seeing my code, what would you suggest as far as coding goes for trying to link it to a more detailed search results page? Qadoshyah Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 31, 2010 Share Posted March 31, 2010 You can try something like this: <?php $dbHost = $dbUser = $dbPass = $dbDatabase = $search = $_POST['search']; if ($search) // perform search only if a string was entered. { $con = mysql_connect($dbHost, $dbUser, $dbPass) or die("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or die("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); $query = "SELECT Appr_Value.Appr_ID as id, Appr_Value.Account, Asmnt_Parcel.OwnersName, Asmnt_Situs.Situs FROM Appr_Value INNER JOIN Asmnt_Parcel ON Appr_Value.Account=Asmnt_Parcel.Account INNER JOIN Asmnt_Situs ON Appr_Value.Account=Asmnt_Situs.Account WHERE Appr_Value.Account LIKE '{$search}' ORDER BY Appr_Value.Account ASC"; $result = mysql_query($query, $con) or die(mysql_error().": $query"); if ($result) { echo "Results:<br><br>"; echo "<table width=90% align=center border=1><tr> <td align=center bgcolor=#4A6B3F>Account</td> <td align=center bgcolor=#4A6B3F>Owners Name</td> <td align=center bgcolor=#4A6B3F>Situs</td> </tr>"; while ($r = mysql_fetch_array($result)) { // Begin while $act = $r["Account"]; $name = $r["OwnersName"]; $situs = $r["Situs"]; echo "<tr> <td><a href='formresults.php?id=".$r['id']."'>$act</td> <td>$name</td> <td>$situs</td> </tr>"; } // end while echo "</table>"; } else { echo "Sorry, please try your search again."; } } else { echo "Start your search"; } ?> Now when user clicks on the link, it takes you to a page similar to this http://www.yourdomain.com/formresults.php?id=1 On formresults.php, make a query like this: $query = "SELECT Appr_Value.Appr_ID as id, Appr_Value.Account, Asmnt_Parcel.OwnersName, Asmnt_Situs.Situs FROM Appr_Value INNER JOIN Asmnt_Parcel ON Appr_Value.Account=Asmnt_Parcel.Account INNER JOIN Asmnt_Situs ON Appr_Value.Account=Asmnt_Situs.Account WHERE Appr_Value.Account LIKE '{$search}' AND Appr_value.Appr_ID = '".mysql_real_escape_string($_GET['id'])."' ORDER BY Appr_Value.Account ASC"; Quote Link to comment Share on other sites More sharing options...
CountryGirl Posted March 31, 2010 Author Share Posted March 31, 2010 You can try something like this: On formresults.php, make a query like this: $query = "SELECT Appr_Value.Appr_ID as id, Appr_Value.Account, Asmnt_Parcel.OwnersName, Asmnt_Situs.Situs FROM Appr_Value INNER JOIN Asmnt_Parcel ON Appr_Value.Account=Asmnt_Parcel.Account INNER JOIN Asmnt_Situs ON Appr_Value.Account=Asmnt_Situs.Account WHERE Appr_Value.Account LIKE '{$search}' AND Appr_value.Appr_ID = '".mysql_real_escape_string($_GET['id'])."' ORDER BY Appr_Value.Account ASC"; Thank you so much!! That worked (www.wagonerassessor.com/searchlink.php). Now, I just gotta get the formresults.php figured out completely. I will probably be back with more questions as I work on the detailed results page . Again, thank you so much! I've been stressin' over how to get this all figured out and couldn't find anywhere on how exactly to do it . Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 31, 2010 Share Posted March 31, 2010 You're welcome miss Quote Link to comment Share on other sites More sharing options...
CountryGirl Posted March 31, 2010 Author Share Posted March 31, 2010 Okay, as I figured, another question. Now, I gotta be able to have the detailed results show up in the appropriate spaces. I'm sure it's not too difficult and it's just a matter of linking the $result to the tables. But, how exactly would I do that? Would I add the table/field name to the right spot in the table HTML and then have it linked back to the PHP coding? Here's the code I have on formresults.php. I know I have some extra coding in there, that I'm not going to use (in the $result) spot, but I'm thinking I probably have to tie in all that table HTML somehow similarily to how the $result table area is. Ideas? Suggestions? [code=php:0]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <?php $dbHost = 'sql5c25d.carrierzone.com'; $dbUser = 'wagonerass854431'; $dbPass = 'W5485H6551'; $dbDatabase = 'fix_wagonerassessor_com'; $con = mysql_connect($dbHost, $dbUser, $dbPass) or die("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or die("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); $query = "SELECT Appr_Value.ApprID as id, Appr_Value.Account, Asmnt_Parcel.OwnersName, Asmnt_Situs.Situs FROM Appr_Value INNER JOIN Asmnt_Parcel ON Appr_Value.Account=Asmnt_Parcel.Account INNER JOIN Asmnt_Situs ON Appr_Value.Account=Asmnt_Situs.Account WHERE Appr_Value.Account LIKE '{$search}' AND Appr_Value.ApprID = '".mysql_real_escape_string($_GET['id'])."' ORDER BY Appr_Value.Account ASC"; $result = mysql_query($query, $con) or die(mysql_error().": $query"); if ($result) { echo "Results:<br><br>"; echo "<table width=90% align=center border=1><tr> <td align=center bgcolor=#4A6B3F>Account</td> </tr>"; while ($r = mysql_fetch_array($result)) { // Begin while $act = $r["Account"]; echo "<tr> <td>$act</td> </tr>"; } // end while echo "</table>"; ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="generator" content="Adobe GoLive" /> <title>Search Results</title> </head> <body background="(EmptyReference!)" bgcolor="#bba86d"> <div align="left"> </div> <div align="center"> <div style="position:relative;width:871px;height:912px;-adbe-g:p;"> <div style="position:absolute;top:384px;left:2px;width:434px;height:138px;"> <table width="434" border="1" cellspacing="2" cellpadding="0"> <tr align="left"> <td><font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Account:</strong></font> <p><font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Name ID:</strong></font></p> <p><font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Address:</strong></font></p> <p><font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Situs:</strong></font></p> </td> </tr> </table> </div> <div style="position:absolute;top:384px;left:436px;width:434px;height:122px;"> <table width="434" border="1" cellspacing="2" cellpadding="0"> <tr> <td> <div align="left"> <font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Instrument Number:</strong></font> <p><font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Grantor:</strong></font></p> <p><font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Sale Date:</strong></font></p> <p><font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Sale Price:</strong></font></p> </div> </td> </tr> </table> </div> <div style="position:absolute;top:544px;left:2px;width:434px;height:69px;"> <table width="434" border="1" cellspacing="2" cellpadding="0"> <tr align="right"> <td> <div align="left"> <font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Legal Description:</strong></font> <p></p> </div> </td> </tr> </table> </div> <div style="position:absolute;top:350px;left:34px;width:800px;height:33px;"> <table width="800" border="1" cellspacing="2" cellpadding="0"> <tr> <td> <div align="center"> <font size="4" color="#003300" face="Georgia, Times New Roman, Times, serif">Wagoner County Public Records Search Results:</font></div> </td> </tr> </table> </div> <div style="position:absolute;top:544px;left:436px;width:434px;height:94px;"> <table width="434" border="1" cellspacing="2" cellpadding="0"> <tr align="right"> <td> <div align="left"> <font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Exemption Type:</strong></font> <p><font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Exemption:</strong></font></p> <p><font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Code:</strong></font></p> </div> </td> </tr> </table> </div> <div style="position:absolute;top:656px;left:1px;width:209px;height:77px;"> <table width="209" border="1" cellspacing="2" cellpadding="0"> <tr> <td> <div align="left"> <font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Land Value:</strong></font></div> <p></p> </td> </tr> </table> </div> <div style="position:absolute;top:656px;left:227px;width:209px;height:77px;"> <table width="209" border="1" cellspacing="2" cellpadding="0"> <tr> <td> <div align="left"> <font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Improvements:</strong></font></div> <p></p> </td> </tr> </table> </div> <div style="position:absolute;top:656px;left:437px;width:209px;height:77px;"> <table width="209" border="1" cellspacing="2" cellpadding="0"> <tr> <td> <div align="left"> <font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Mobile Home:</strong></font></div> <p></p> </td> </tr> </table> </div> <div style="position:absolute;top:656px;left:659px;width:209px;height:69px;"> <table width="209" border="1" cellspacing="2" cellpadding="0"> <tr> <td> <div align="left"> <font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Total Value:</strong></font> <p></p> </div> </td> </tr> </table> </div> <div style="position:absolute;top:752px;left:128px;width:306px;height:69px;"> <table width="306" border="1" cellspacing="2" cellpadding="0"> <tr> <td> <div align="left"> <font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Assessed Value:</strong></font> <p></p> </div> </td> </tr> </table> </div> <div style="position:absolute;top:752px;left:436px;width:306px;height:69px;"> <table width="306" border="1" cellspacing="2" cellpadding="0"> <tr> <td> <div align="left"> <font size="2" color="#352200" face="Georgia, Times New Roman, Times, serif"><strong>Total Taxable:</strong></font> <p></p> </div> </td> </tr> </table> </div> <div style="position:absolute;top:0px;left:111px;width:648px;height:350px;"> <img src="toplogo3.jpg" alt="" height="350" width="648" border="0" /></div> </div> <p></p> </div> </body> </html> [/code] Thank you! Quote Link to comment 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.