Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How can I make this a link? Can you fix my code?
Old 02-12-2008, 12:08 PM How can I make this a link? Can you fix my code?
Extreme Talker

Posts: 176
Name: Aaric
Trades: 0
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?
aaricwon is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-12-2008, 12:36 PM Re: How can I make this a link? Can you fix my code?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Try this:

PHP Code:
echo '<td><a href="fighter_bio.php?id='.$id.'">'.$row['field_6']."</a></td>"
Now, I highly advise that you study each and every change I made there -- it will help you be a better PHP programmer.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 02-12-2008, 12:39 PM Re: How can I make this a link? Can you fix my code?
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
You want the contents of $row['field_6'] to be the anchor text and $id to be part of the query string??


PHP Code:
  echo "<td><a href='fighter_bio.php?id=$id'>".$row['field_6']."</a></td>"
I personally think its easier and a shade more efficient if you dip out of php where possible. In the above example you would just echo the two variables and come out of php for the html http://uk.php.net/language.basic-syntax
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 02-12-2008, 12:48 PM Re: How can I make this a link? Can you fix my code?
Extreme Talker

Posts: 176
Name: Aaric
Trades: 0
Thanks guys. Still working on it... The link still isn't working.
You can see it here: http://www.bjjnews.org/TUF/fighterdb...h.php?search=f

HTML 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>";
aaricwon is offline
Reply With Quote
View Public Profile
 
Old 02-12-2008, 12:51 PM Re: How can I make this a link? Can you fix my code?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Page didn't load. Instead of saying "isn't working", please say how it's not working the way you intended. All code works, just not the way you intend.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 02-12-2008, 12:58 PM Re: How can I make this a link? Can you fix my code?
Extreme Talker

Posts: 176
Name: Aaric
Trades: 0
Quote:
Originally Posted by aaricwon View Post
Thanks guys. Still working on it... The link still isn't working.
You can see it here: http://www.bjjnews.org/TUF/fighterdb...h.php?search=f

HTML 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>";
Sorry about that. What I meant was exactly what you said. It isn't working the way I intended. I want it to specify the id in the link and open up the entire record.
aaricwon is offline
Reply With Quote
View Public Profile
 
Old 02-12-2008, 01:17 PM Re: How can I make this a link? Can you fix my code?
Extreme Talker

Posts: 176
Name: Aaric
Trades: 0
each link is the same I just noticed.
see it here: http://www.bjjnews.org/TUF/fighterdb...h.php?search=b

all of my code:

PHP 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);
}
?>
aaricwon is offline
Reply With Quote
View Public Profile
 
Old 02-12-2008, 02:36 PM Re: How can I make this a link? Can you fix my code?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
It's just that you're not accessing the ID correctly.

Change
PHP Code:
echo "<td><a href='fighter_bio.php?id=$id'>".$row['field_1']."</a></td>"
to

PHP Code:
echo "<td><a href='fighter_bio.php?id=".$row['id']."'>".$row['field_1']."</a></td>"
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 02-12-2008, 02:46 PM Re: How can I make this a link? Can you fix my code?
Extreme Talker

Posts: 176
Name: Aaric
Trades: 0
Quote:
Originally Posted by aaricwon View Post
each link is the same I just noticed.
see it here: http://www.bjjnews.org/TUF/fighterdb...h.php?search=b

all of my code:

PHP 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);
}
?>
THANK YOU SO MUCH!!
aaricwon is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How can I make this a link? Can you fix my code?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.36090 seconds with 12 queries