aaricwon Posted February 12, 2008 Share Posted February 12, 2008 First of all... THANKS to everyone here. I am new to this and know nothing compared to you guys but everyone has been very nice and hasn't gone out of their way to make me feel dumb for not knowing this stuff. My question, I am working on displaying data from a mysql database I want PHP Code: echo "<td >".$row['field_6']."</td>"; to be a link. I tried this: PHP Code: echo "<td><a href=\"fighter_bio.php?id=<? echo $id; ?>\".$row['field_6]."</a></td>"; but it didn't seem to work. Does anyone have any suggestions for fixing this code? Quote Link to comment https://forums.phpfreaks.com/topic/90732-how-can-i-make-this-code-a-link/ Share on other sites More sharing options...
revraz Posted February 12, 2008 Share Posted February 12, 2008 You are trying to put PHP tags inside of php tags echo "<td><a href=\"fighter_bio.php?id=$id\">".$row['field_6]."</a></td>"; Quote Link to comment https://forums.phpfreaks.com/topic/90732-how-can-i-make-this-code-a-link/#findComment-465060 Share on other sites More sharing options...
aaricwon Posted February 12, 2008 Author Share Posted February 12, 2008 Thanks everyone... Still no luck ??? but I'm working on it and hope to learn something new... Here is my code: echo "<tr>"; echo "<td><a href=\"fighter_bio.php?id=$id\">".$row['field_1]."</a></td>"; echo "<td><b>".$row['field_2']."</b></td>"; echo "<td>".$row['field_8']."</td>"; echo "<td>".$row['field_4']."</td>"; echo "<td>".$row['field_5']."</td>"; echo "<td >".$row['field_6']."</td>"; echo "</tr>"; You can see it (not working) here: http://www.bjjnews.org/TUF/fighterdb/search/search.php?search=f The link doesn't specify the id Quote Link to comment https://forums.phpfreaks.com/topic/90732-how-can-i-make-this-code-a-link/#findComment-465087 Share on other sites More sharing options...
marcus Posted February 12, 2008 Share Posted February 12, 2008 $id isn't defined... Quote Link to comment https://forums.phpfreaks.com/topic/90732-how-can-i-make-this-code-a-link/#findComment-465092 Share on other sites More sharing options...
Illusion Posted February 12, 2008 Share Posted February 12, 2008 echo "<td><a href=\"fighter_bio.php?id=".$id."\">".$row['field_1]."[/url]</td>"; Quote Link to comment https://forums.phpfreaks.com/topic/90732-how-can-i-make-this-code-a-link/#findComment-465112 Share on other sites More sharing options...
aaricwon Posted February 12, 2008 Author Share Posted February 12, 2008 actually... they are all showing up w/the same link? see it here: http://www.bjjnews.org/TUF/fighterdb/search/search.php?search=b my code: <?php // connect to the mysql database server. mysql_connect ($dbhost, $dbusername, $dbuserpass); //select the database mysql_select_db($dbname) or die('Cannot select database'); //search variable = data in search box or url if(isset($_GET['search'])) { $search = $_GET['search']; } //trim whitespace from variable $search = trim($search); $search = preg_replace('/\s+/', ' ', $search); //seperate multiple keywords into array space delimited $keywords = explode(" ", $search); //Clean empty arrays so they don't get every row as result $keywords = array_diff($keywords, array("")); //Set the MySQL query if ($search == NULL or $search == '%'){ } else { for ($i=0; $i<count($keywords); $i++) { $query = "SELECT * FROM registering_fighters " . "WHERE id LIKE '%".$keywords[$i]."%'". " OR field_1 LIKE '%".$keywords[$i]."%'" . " OR field_2 LIKE '%".$keywords[$i]."%'" . " OR field_8 LIKE '%".$keywords[$i]."%'" . " OR field_4 LIKE '%".$keywords[$i]."%'" . " OR field_5 LIKE '%".$keywords[$i]."%'" . " OR field_6 LIKE '%".$keywords[$i]."%'" . " ORDER BY field_2"; } //Store the results in a variable or die if query fails $result = mysql_query($query) or die(mysql_error()); $id=mysql_result($result,$i,"id"); } if (isset ($_GET['id'])) { $id = $_GET['id']; } if ($search == NULL or $search == '%'){ } else { //Count the rows retrived $count = mysql_num_rows($result); } echo "<html>"; echo "<head>"; echo "<title>Tuff-N-Uff Fighter Database</title>"; echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />"; echo "</head>"; echo "<body onLoad=\"self.focus();document.searchform.search.focus()\">"; echo "<center>"; echo "<br /><form name=\"searchform\" method=\"GET\" action=\"search.php\">"; echo "<input type=\"text\" name=\"search\" size=\"15\" TABINDEX=\"1\" />"; echo " <input type=\"submit\" value=\"Search\" />"; echo "</form>"; //If search variable is null do nothing, else print it. if ($search == NULL) { } else { echo "You searched for <b><FONT COLOR=\"blue\">"; foreach($keywords as $value) { print "$value "; } echo "</font></b>"; } echo "<p> </p><br />"; echo "</center>"; //If users doesn't enter anything into search box tell them to. if ($search == NULL){ echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>"; } elseif ($search == '%'){ echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>"; //If no results are returned print it } elseif ($count <= 0){ echo "<center><b><FONT COLOR=\"red\">Your query returned no results from the database.</font></b><br /></center>"; //ELSE print the data in a table } else { //Table header //Colors for alternation of row color on results table $color1 = "#d5d5d5"; $color2 = "#e5e5e5"; //While there are rows, print it. while($row = mysql_fetch_array($result)) { //Row color alternates for each row $row_color = ($row_count % 2) ? $color1 : $color2; //table background color = row_color variable echo "<center><table bgcolor=".$row_color." width=\"750\">"; echo "<tr>"; echo "<td><a href='fighter_bio.php?id=$id'>".$row['field_1']."</a></td>"; echo "<td><b>".$row['field_2']."</b></td>"; echo "<td>".$row['field_8']."</td>"; echo "<td>".$row['field_4']."</td>"; echo "<td>".$row['field_5']."</td>"; echo "<td >".$row['field_6']."</td>"; echo "</tr>"; echo "</table></center>"; $row_count++; //end while } //end if } echo "</body>"; echo "</html>"; if ($search == NULL or $search == '%') { } else { //clear memory mysql_free_result($result); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90732-how-can-i-make-this-code-a-link/#findComment-465138 Share on other sites More sharing options...
marcus Posted February 12, 2008 Share Posted February 12, 2008 I think you want to echo: $row['id'] //not $id by the way if you don't want random searches don't include the allowment of "_" being searched Quote Link to comment https://forums.phpfreaks.com/topic/90732-how-can-i-make-this-code-a-link/#findComment-465141 Share on other sites More sharing options...
aaricwon Posted February 12, 2008 Author Share Posted February 12, 2008 I tried echoing $row['id'] but when I upload that, the page can't be displayed. Thanks. Still working on it :-\ Quote Link to comment https://forums.phpfreaks.com/topic/90732-how-can-i-make-this-code-a-link/#findComment-465188 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.