Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/90732-how-can-i-make-this-code-a-link/
Share on other sites

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

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);

}

?>

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.