Forum Moderators: coopster

Message Too Old, No Replies

link images to website address in DB

         

tecun

10:07 pm on Oct 24, 2008 (gmt 0)

10+ Year Member



Greetings,just wondering if anyone had an idea or had a source that could showed me how to link a website address stored in a database onto an image in my computer so when the user clicks on the image that will automatically take them to the corresponding site.

NeilsPHP

9:22 pm on Oct 25, 2008 (gmt 0)

10+ Year Member



hi,

"how to link a website address stored in a database onto an image in my computer"

I could not understd as to what you mean by that..but I guess you are trying to hyperlink a picture to a website address saved in db.if that's the case,this is how i will do it.
1.connect to db & get the column/row data using LIST command
2.save website address in a variable ..like $ADDRESS = "www.sitenameexample.com"; //this will be value from db from step 1
3.rest should be something like.. echo" <a href='$ADDRESS'> <img src = 'path to picture'> </a> ";

hope that helps

tecun

10:54 pm on Oct 28, 2008 (gmt 0)

10+ Year Member



sorry if i dind't word it properly however what I have been attempting to do is the following.
from my select statements I get two columns of data one is a website address and the other one is the path for picture of the logo for the website address.
I was able to display the website address however now I'm trying to define the path of where the picture is stored, but I'm not sure how to single out the "logo" column, as you can see the select statement is calling the link and the logo, but I'm lost of how to include the picture from the path and how to single out the array to only display the logo column.
here is my code

echo "<table>";

$sql="select link, logo from testlogo order by logo";

$array = array();
if(mysql_query($sql))
{
$check=mysql_query($sql);
while($row=mysql_fetch_row($check)){
$array[] = $row[0];
}
}
$cols = 3;

$count = count($array);
if($count%$cols > 0){
for($i=0;$i<($cols-$count%$cols);$i++){
$array[] = '&nbsp;';
}
}
echo "<table border=\"3\">\r\n";

foreach($array as $key => $link){
if($key%$cols == 0) echo "<tr>\r\n";
echo "<td><a href='$link'><img src='$logo' alt='test' /></a></td>\r\n";
if($key%$cols == ($cols - 1)) echo "</tr>\r\n";
}
echo "</table>";

?>

mooger35

11:01 pm on Oct 28, 2008 (gmt 0)

10+ Year Member



Now, try this: (still untested)

echo "<table>";

$sql="select link, logo from testlogo order by logo";

$array = array();
if(mysql_query($sql))
{
$check=mysql_query($sql);
while($row=mysql_fetch_row($check)){
$array[] = "<a href=\"$row[0]\"><img src=\"$row[1]\" alt=\"test\" /></a>";
}
}
$cols = 3;

$count = count($array);
if($count%$cols > 0){
for($i=0;$i<($cols-$count%$cols);$i++){
$array[] = '&nbsp;';
}
}
echo "<table border=\"3\">\r\n";

foreach($array as $key => $link){
if($key%$cols == 0) echo "<tr>\r\n";
echo "<td>$link</td>\r\n";
if($key%$cols == ($cols - 1)) echo "</tr>\r\n";
}
echo "</table>";

?>

tecun

1:34 pm on Oct 29, 2008 (gmt 0)

10+ Year Member



Thank you Mooger, I owe you a beer or coffee?
well you were dead on it, anything I can do just let me know.

mooger35

3:26 pm on Oct 29, 2008 (gmt 0)

10+ Year Member



lol... no problem.

I've been helped out on here countless times.