We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Display record with image link

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.

4
Contributors
6
Replies
2 Days
Discussion Span
1 Year Ago
Last Updated
8
Views
gilanib
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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'];?>">
Karthik_pranas
Posting Pro
571 posts since Feb 2011
Reputation Points: 96
Solved Threads: 101
Skill Endorsements: 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?

diafol
Keep Smiling
Moderator
10,842 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,537
Skill Endorsements: 61

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

gilanib
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

gilanib
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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)

diafol
Keep Smiling
Moderator
10,842 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,537
Skill Endorsements: 61

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

marases
Junior Poster in Training
92 posts since Sep 2010
Reputation Points: 21
Solved Threads: 7
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.1357 seconds using 2.73MB