<?php
// open base
 $con = mysql_connect("xxxxxxxxxxx", "xxxxxxxxxxx", "xxxxxxxxxxxxxxxxxx");
 if (!$con)
{
 die('Could not connect: ' . mysql_error());
  }
mysql_select_db("xxxxxxxxxxx", $con);
// open table
$result = mysql_query("SELECT * FROM leader");

// print table & column headders
echo "<table border='1'>
<tr>
<th>id</th>
<th>Club</th>
<th>Website</th>
<th>Club Badge Url</th>
</tr>";

// get data to fill table
while($row = mysql_fetch_array($result))
  
  {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['club'] . "</td>";
  
// gets website url and makes it clickable
echo "<td><a class=\"mylink\" href=\"" . $row['website'] . "\">" . $row['website'] . "</a></td>";

//gets pic. url and displays in box 78 x 78
  echo "<td>" . $row['url'] . "</td>";


 echo "</tr>";
  }
echo "</table>";

// close base
mysql_close($con);
?>

I am working on the above code and have 2 problems {so far}

1/ the links end up like " mysite.com/www.outputsite.com " insted of "www.outputsite.com "

2/ trying to get the url to become a pic insted of just text.

thanks in advance.

Member Avatar for diafol

echo out your $row to see if it's garbled.

echo "<td>" . $row['url'] . "</td>";

This will not display an image - you need to include an image tag:

echo "<td><img src=\"" . $row['url'] . "\" /></td>";

BTW - you may consider using alt attributes for images and title attributes for links.

You can break out of the php tags to make it a bit more manageable:

<td><a class="mylink" href="<?php 'www.'.$row['website']; ?>"> <?php echo "www.$row['website']" ?></a></td>

You'll also need an image link for the thumbnail...

<td> <img src="/path/of/image" alt="image description" href="<?php $row['url'] ?>" height="78px" width="78px"></td>

This prints "www.outputsite.com" and the link URL will be exactly the same. I think that's the solution to the problem as I understand it anyway

Member Avatar for diafol

OK, few things

1) You must place 'http://' in front of your urls or they will point to a page in your site.
2) your images don't exist. Some are truncated - so increase the size of your db field. These also require the 'http://' in front of them.

OK, few things

1) You must place 'http://' in front of your urls or they will point to a page in your site.
2) your images don't exist. Some are truncated - so increase the size of your db field. These also require the 'http://' in front of them.

i understand that, not a clue how , do i do it in the mysqul data base or in the code above ?

have been looking in the database to add it, cant see where, have loaded sum full url`s in there az defult pics and they still dont show.

for the link line
echo "<td><a class=\"mylink\" 'http://' href=\"http://" . $row . "\">" . $row . "</a></td>";

WORKS

still stuck getting image link to show.

i understand that, not a clue how , do i do it in the mysqul data base or in the code above ?

have been looking in the database to add it, cant see where, have loaded sum full url`s in there az defult pics and they still dont show.

for the link line
echo "<td><a class=\"mylink\" 'http://' href=\"http://" . $row . "\">" . $row . "</a></td>";

WORKS

still stuck getting image link to show.

Have got image to show with ,

echo "<td><img class=\"image\" src=\"http://" . $row . "\" /></td>";

not got to resizing yet as if the link allready has "http://" when stored it adds it again. trying to learn how to filter the input or output

Member Avatar for diafol

resizing is easy - just apply one dimension, the other will be constrained (same scale):

width="200"

This will display a 400px X 600px [width X height] as 200px X 300px.

resizing is easy - just apply one dimension, the other will be constrained (same scale):

width="200"

This will display a 400px X 600px [width X height] as 200px X 300px.

echo "<td><img class=\"image\" ' width="200" ' src=\"http://" . $row . "\" /></td>";

where is this wrong please ?

Member Avatar for diafol

seems ok to me. Maybe the image is protected if you are trying to access an image on a remote site. Unless you're using some css or js for the class="image", you don't really need it.
I suggest you hard code what you expect into a plain html file and see if that works:


//edit

OK now I see, you've placed some ' ... ' single quotes in your code - just delete these. If it still doesn't work, try hard coding html into a plain html file to see if that works:

<img class="image" width="200" src="http://www.site.com/image.jpg" />

Obviously change the src to something that is in your DB.

seems ok to me. Maybe the image is protected if you are trying to access an image on a remote site. Unless you're using some css or js for the class="image", you don't really need it.
I suggest you hard code what you expect into a plain html file and see if that works:


//edit

OK now I see, you've placed some ' ... ' single quotes in your code - just delete these. If it still doesn't work, try hard coding html into a plain html file to see if that works:

<img class="image" width="200" src="http://www.site.com/image.jpg" />

Obviously change the src to something that is in your DB.

this line works , only it gives the image as any size it gets from the url`s ,

echo "<td><img src=\"http://" . $row . "\" /></td>";


this line

echo "<td><img src=\"http://" . $row . "\" /></td>"; width = "75"

dos not, no matter where i place the " width " part,

The width is part of the image tag

echo "<td><img width = '75' src='http://". $row['url'] . "' /></td>";
commented: works a treet thanks +1
Member Avatar for diafol

or even:

echo '<td><img class="img" width = "75" src="http://' . $row['url'] . '" /></td>';
commented: thanks took your advice and dropped the class. +1

CHANGE X to your own settings . thanks everyone

<?php

// add data base conections
 $con = mysql_connect("xxxxxxxxxx", "xxxxxxxxxxx", "xxxxxxxxxx");
 if (!$con)
{
 die('Could not connect: ' . mysql_error());
  }
mysql_select_db("xxxxxxxxxxxx", $con);

$result = mysql_query("SELECT * FROM leader");

echo "<table border='9'>
<tr>
// table headders
<th>xxx1xxxxx</th>
<th>xxx2xxxx</th>
<th>xxx3xxxx</th>
<th>xxx4xxxx Url</th>
</tr>";

while($row = mysql_fetch_array($result))
  
  {
  echo "<tr>";
  echo "<td>" . $row['X1'] . "</td>";
  echo "<td>" . $row['X2'] . "</td>";

  // clickable link
echo "<td><a class=\"mylink\" 'http://' href=\"http://" . $row['X3'] . "\">" . $row['X3'] . "</a></td>";

 // image from a url at width size
echo "<td><img width = '75' src='http://". $row['x4'] . "' /></td>";

 echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?> 
<html>
<body>


<a href="res.php">Link text</a> 
Click on <a href="www.link.here">this link</a> to run your first PHP script. 
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.