1,105,225 Community Members

Display record with image link

Member Avatar
gilanib
Newbie Poster
3 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Greetings!
I have a website www.lanceronlinejobs.com/our_franchises.php I have a franchise images. I want to display each franchise record from database whenever a user click on franchise link. Here is my code.
ourfranchises.php code:

<?php 
include('fconnection.php');

$sql = mysql_query("SELECT * FROM tbl_franchise ORDER BY id DESC") or die(mysql_error());
$row3 = mysql_fetch_array($sql); 
?>
<a href="franchiseDetails.php?city=<?php echo $row3['city'];?>"><img src="images/lbatkhela.jpg" width="150" height="150" alt="Batkhela" /></a>

----------------------------------------------------------------------

franchiseDetails.php code:

<?php
$id = $_GET['id'];
					
$query = "SELECT * FROM tbl_franchise WHERE id = '$id' ORDER BY id DESC LIMIT 1";

$result = mysql_query($query);

if (!$result) {
echo "NO RECORD FOUND";
} else {

while($row3 = mysql_fetch_array($result)):
?>

Manager Name: <?php echo $row3['manager_name'];?>

Please help me. Any help would be appreciated.

Thanks.

Member Avatar
karthik_ppts
Posting Pro
574 posts since Feb 2011
Reputation Points: 81 [?]
Q&As Helped to Solve: 101 [?]
Skill Endorsements: 1 [?]
 
0
 

In this line

<a href="franchiseDetails.php?city=<?php echo $row3['city'];?>">

pass your record id instead of city as follows

<a href="franchiseDetails.php?id=<?php echo $row3['id'];?>">
Member Avatar
diafol
Where are my eyes?
12,941 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,845 [?]
Skill Endorsements: 90 [?]
Moderator
Featured
Sponsor
 
0
 

I want to display each franchise record from database whenever a user click on franchise link.

DO we assume you mean to display data from ONE record based on the city parameter in the url?

Member Avatar
gilanib
Newbie Poster
3 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

In this line

<a href="franchiseDetails.php?city=<?php echo $row3['city'];?>">

pass your record id instead of city as follows

<a href="franchiseDetails.php?id=<?php echo $row3['id'];?>">

Dear it display one single id for all image links. See the result on http://lanceronlinejobs.com/our_franchises.php

Member Avatar
gilanib
Newbie Poster
3 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

DO we assume you mean to display data from ONE record based on the city parameter in the url?

Yes dear. Please help me out.

Member Avatar
diafol
Where are my eyes?
12,941 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,845 [?]
Skill Endorsements: 90 [?]
Moderator
Featured
Sponsor
 
0
 
<?php 
include('fconnection.php');
 
$sql = mysql_query("SELECT * FROM tbl_franchise ORDER BY id DESC") or die(mysql_error());
$row3 = mysql_fetch_array($sql); 
?>
<a href="franchiseDetails.php?city=<?php echo $row3['city'];?>"><img src="images/lbatkhela.jpg" width="150" height="150" alt="Batkhela" /></a>

This will just print one city link (the first one) as you don't have a while loop. No text is shown with this link, just an image. Tooltip (alt) - try using 'title' attribute too.

Is this what you want? Seems wrong to query the whole tbl_franchise table and then just use the first record.

==============

<?php
$id = $_GET['id'];
 
$query = "SELECT * FROM tbl_franchise WHERE id = '$id' ORDER BY id DESC LIMIT 1";
 
$result = mysql_query($query);
 
if (!$result) {
echo "NO RECORD FOUND";
} else {
 
while($row3 = mysql_fetch_array($result)):
?>
 
Manager Name: <?php echo $row3['manager_name'];?>

I'm assuming this is coming from the previous script link. Again this makes little sense as you're ORDERING BY id, but limiting it to one id, which I assume is unique. Odd.

For this recordset, you one have one record, but then go on to loop over it with a 'while'. This makes no sense.

You seem to have mixed up the purpose of using a loop.

BTW: your get variable should be $_GET not $_GET

I recommend you have a look at the php.net site and learn the basics of loops (for, while, do)

Member Avatar
marases
Junior Poster in Training
93 posts since Sep 2010
Reputation Points: 11 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi, well first thing your passing the variable city to the franchiseDetails.php file, and asking for the id variable...

So just change this and it should work.

<a href="franchiseDetails.php?id=<?php echo $row3['id'];?>"><img src="images/lbatkhela.jpg" width="150" height="150" alt="Batkhela" /></a>

Thanks,
Marais

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: