Current location: Hot Scripts Forums » Programming Languages » PHP » Make a query that makes a field a link to the entire row


Make a query that makes a field a link to the entire row

Reply
  #1 (permalink)  
Old 10-08-03, 09:22 AM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Make a query that makes a field a link to the entire row

I'm wondering if its possible to do this. My table has, lets say, 7 fields per row
( no problem ). I do a query that displays only 3 of those fields ( still no problem ). I want one of the 3 fields I display to act as a link, which will display all 7 fields in the same row the 3 fields came from ( thats the problem ). An example of why to do this would be, say, a book database. The original query ( 3 fields ) list the author, book title, and brief description, and the book title would act as a link, which when clicked would display ( perhaps go to another page? ) all 7 of the fields of that books row.
Say the table is set up as this...

id, author, book_title, brief_desc, description, submitted_by, date

Any suggestions?
Reply With Quote
  #2 (permalink)  
Old 10-08-03, 09:44 AM
Chroder Chroder is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Toronto, Ontario
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
The easiest would just make the link go to another page with different results. Unless you wanted DHTML effects or a javascript popup window.
__________________
DevBox.net | DevBoxForums.com
Reply With Quote
  #3 (permalink)  
Old 10-08-03, 10:32 AM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Quote:
Originally Posted by Chroder
The easiest would just make the link go to another page with different results. Unless you wanted DHTML effects or a javascript popup window.
Make the name/link basically into a another query that would display the entire row? That would work, I'll give it a shot. Don't really want pop-ups if I can help it. Thnx for the idea. I had tried multiple tables in which one was supposed to link to the other, but I couldnt get it set up correctly.
Reply With Quote
  #4 (permalink)  
Old 10-08-03, 02:08 PM
Chroder Chroder is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Toronto, Ontario
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Make a link to another page and in the query string include the id. Ex:

PHP Code:

echo '<a href="displaydetails.php?id="'.$row['id'].'">click here for more details</a>'
Then on the next page you can create a mySQL query to get the one specific row. Ex:

PHP Code:

$id $_GET['id'];

$sql "SELECT * FROM mytable WHERE id=$id"
__________________
DevBox.net | DevBoxForums.com
Reply With Quote
  #5 (permalink)  
Old 10-08-03, 03:42 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Quote:
Originally Posted by Chroder
Make a link to another page and in the query string include the id. Ex:

PHP Code:

echo '<a href="displaydetails.php?id="'.$row['id'].'">click here for more details</a>'
Then on the next page you can create a mySQL query to get the one specific row. Ex:

PHP Code:

$id $_GET['id'];

$sql "SELECT * FROM mytable WHERE id=$id"
I tried something just like that, but it was with 2 tables, and it wasnt working right. I was thinking of doing it exactly the way your talking about with one table. Let me see if I get this right in this example...

Lets say the first query displays this...

Author
Book Title
Brief Description
echo '<a href="displaydetails.php?id="'.$row['id'].'">See More</a>';

That link goes to a page called displaydetails.php, where it show the entire row.
Don't mean to sound repetitive of what you replied, just wanted to see if I got it right before I try it out. Thnx alot.
Reply With Quote
  #6 (permalink)  
Old 10-08-03, 04:10 PM
Chroder Chroder is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Toronto, Ontario
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Yep, thats the idea. Of course, your $row['id'] is going to have to exist
__________________
DevBox.net | DevBoxForums.com
Reply With Quote
  #7 (permalink)  
Old 10-08-03, 05:01 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Part of my code...

while ($i < $num):
$id=mysql_result($result,$i,"id"); (the field ID)

echo '<a href="listing.php?id="'.$row['id'].'">See It Here</a>'


Parse error: parse error, expecting `','' or `';''
on the line you gave me.

???
Reply With Quote
  #8 (permalink)  
Old 10-08-03, 06:21 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
I decided to try this as a song lyric database instead.

This is the pertinent php code to pull up the row id, artist name, and song title.

$query=("SELECT id,artist_name,song_title FROM artist WHERE artist_name LIKE '$searchartist' OR song_title LIKE '$searchtitle' OR category LIKE '$searchcategory'");
$result = mysql_query($query);
$num=mysql_num_rows($result);
$i = 0;
echo "<TABLE width=450 border=0 align=center cellpadding=4 cellspacing=0>
<tr>
<td width=30 align=center bgcolor=white><font face=verdana size=2><b>See It</b></font></td>
<td width=215><font face=verdana size=2><b>Artist</b></font></td>
<td width=215><font face=verdana size=2><b>Song Title</b></font></td></tr><tr>";
while ($i < $num):
$id=mysql_result($result,$i,"id");
$artist_name=mysql_result($result,$i,"artist_name" );
$song_title=mysql_result($result,$i,"song_title");

echo "<td bgcolor=white> '<a href="listing.php?id="'.$row['id'].'">See It Here</a>';</td><td bgcolor=white>$artist_name</td><td bgcolor=white>$song_title</td>";
echo "</tr>";

The link to go to the next page to display the row is where I keep getting a parse error...
Parse error: parse error, expecting `','' or `';''

Am i missing something?
Reply With Quote
  #9 (permalink)  
Old 10-09-03, 06:18 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Got it working...thnx for the help
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Query Dump for blob field type ridwank PHP 4 06-20-03 11:35 AM


All times are GMT -5. The time now is 06:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.