Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking an image to a url stored in the same record set

Status
Not open for further replies.

padaman420

Programmer
Jan 24, 2006
15
CA
I would like to know how to apply a link to the an image, the url is stored in the same recordset as the image.

And also I would like to know the php code that would allow me to post a url from a database entry. Cause right now the infomation that shows up on my page is plain text and I would like it to show the info as a url.

I.E in my table I have a field called related links and the information that I put in the field are urls pointing a specific page on my site.



 
for the url just echo out the full html for an hyperlink:
Code:
echo "<a href=\"". $path . "\">Clickable Text </a>";
.

for the link attach an onclick event to the <img> tag or add the img tag between <a></a> links
 
All you really have to do is ouptut the adequate markup for a link:

Code:
$mylink="[URL unfurl="true"]http://www.google.com";[/URL]

echo [red]"<a href='"[/red] [green]. [/green][blue]$mylink[/blue][green] .[/green][red] "'>This is a link</a>"[/red];

The variable can be whatever contains your URL info coming from the DB.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
quote " for the link attach an onclick event to the <img> tag or add the img tag between <a></a> links"

the link is store in the database with the image in another field, how do i apply it to the onclic procedure.

I'm a newbie to php.
 
However you get the values from the DB,
Just output the image and link and surround it with the correct markup like so:

Code:
echo [red]"<a href='"[/red] . [blue] $link[/blue] . [red]"'><img src='"[/red] . [blue]$imgsrc[/blue] . [red]"'></a>"[/red];

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Yes your link can equal a field.

$mylink= $results['mydbfield'];

Or however it is your getting the values from the Database.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
this is the code generated by dreamweaver mx
-----------------------------------------------------------
$maxRows_featured_event = 4;
$pageNum_featured_event = 0;
if (isset($_GET['pageNum_featured_event'])) {
$pageNum_featured_event = $_GET['pageNum_featured_event'];
}
$startRow_featured_event = $pageNum_featured_event * $maxRows_featured_event;

mysql_select_db($database_indamix, $indamix);
$query_featured_event = "SELECT name, photo, related_link FROM featured_event";
$query_limit_featured_event = sprintf("%s LIMIT %d, %d", $query_featured_event, $startRow_featured_event, $maxRows_featured_event);
$featured_event = mysql_query($query_limit_featured_event, $indamix) or die(mysql_error());
$row_featured_event = mysql_fetch_assoc($featured_event);

if (isset($_GET['totalRows_featured_event'])) {
$totalRows_featured_event = $_GET['totalRows_featured_event'];
} else {
$all_featured_event = mysql_query($query_featured_event);
$totalRows_featured_event = mysql_num_rows($all_featured_event);
}
$totalPages_featured_event = ceil($totalRows_featured_event/$maxRows_featured_event)-1;
------------------------------------------------------------

Where would I insert the following code:

$mylink= $results['related_link'];
 
Or can I just add a php tag in my dynamic table to fetch the information.
 
That's only part of the code, Where does Dreamweaver display the actual fields?

There should be either a [blue]print[/blue], or an [blue]echo[/blue] command somewhere that looks like:
Code:
echo $row_featured_event['related_link'];

or something similar.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Ok I found it, now how would I format it now so i get the expected end result
 
It should be something like:

Code:
echo [red]"<a href='"[/red] . [blue]$row_featured_event[[maroon]'related_link'[/maroon]][/blue] . [red]"'>
<img src='"[/red] .  [blue]$row_featured_event[[maroon]'image'[/maroon]][/blue] . [red]"'></a>"[/red];

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
First off thanks for your patiente in this case,

ok whe're almost there !!

The issue i'm havving id that the link is actually pointing to the actual directory my page is in plus the url at the end instead of pointing to an external url (ie ../news/ ). plus I need to link to open the link in a "_blank" page. and the text that should appear on my page is the same as the url information.

Thanks again for all your precious help.
 
For the URL to work, it needs to be complete, i.e have the http:// in front.

If the fields in the DB don't have it you'll have to add it manually. like so:
Code:
echo "<a href='[purple]http://[/purple]" . $row_featured_event['related_link'] . "'>
<img src='" .  $row_featured_event['image'] . "'></a>";

Second to get it to open in a blank page add target=_blank to the link.

Code:
echo "<a href='[purple]http://[/purple]" . $row_featured_event['related_link'] . "' [green]target='_blank'[/green]>
<img src='" .  $row_featured_event['image'] . "'></a>";

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I use Interakt extensions for my file upload behavior.

this is the code it generates for my image source

<?php echo tNG_showDynamicImage("../", "../featured_event/", "{featured_event.photo}");?>


Where would I put it in this code for it to work

<img src='" . $row_featured_event['image'] . "'></a>";
 
I am not familiar with Interakt, but from the looks of it I would guess you could just stick the link around the tng function.

Code:
echo "<a href='[URL unfurl="true"]http://"[/URL] . $row_featured_event['related_link'] . "' target='_blank'>" . [red]tNG_showDynamicImage("../", "../featured_event/", "{featured_event.photo}");[/red] . "</a>";
If that doesn't work,then maybe somoeone else here who knows the extensions can help us out.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
It didn't work but if someone finds out let me know !!

For the rest everything is working fine !!

Thanks a laot for all your help.

My first issue treated on this community but it was very effective !!
 
Was there some error associated with it?
If you look at the source code from the browser what does it look like?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Would it be because there's no img src tag in the code ???
 
I can't really answer that as I have no idea waht the [red]tNG_showDynamicImage("../", "../featured_event/", "{featured_event.photo}");[/red] returns.

It c ould verywell return the Img src tag, or maybe it doesn't.

You could try adding the img src tag and placing the [red]tNG_showDynamicImage("../", "../featured_event/", "{featured_event.photo}");[/red] funtion in the src part.

like:

Code:
<img src='" . tNG_showDynamicImage("../", "../featured_event/", "{featured_event.photo}") . "'>

And see if that works.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top