Jump to content

[SOLVED] Quick Question: Echo An Image From MySQL, I got it but...


suttercain

Recommended Posts

Quick Question: Echo An Image From MySQL, I got it but...

I need to add tb_ in front of the 'image.jpg' so it'll actually echo 'tb_image.jpg'

 

CODE

echo "<td><img src=$row[cover]></td>";

 

I tried:

echo "<td><img src=$rowtb_[cover]></td>";

But of course it didn't work...

 

Any suggestions? Thanks.

Link to comment
Share on other sites

Hey MadTechie,

 

Thanks for the reply. I tried both but neither worked out for me:

 

echo "<td><img src=tb_$row[cover]></td>";

resulted in the following image path:

http://localhost/Superman/tb_images/520027.jpg (Should be http://localhost/Superman/images/tb_520027.jpg to work)

 

And the other code:

$X = "tb_".$row[cover];
<td><img src=$X></td>;

resulted in the following image path:

http://localhost/Superman/tb_

 

I know, I have tried different ways but so far no luck. Any other suggestions?

 

Thanks.

Link to comment
Share on other sites

OK the reason for that is because $row[cover]  = "images/520027.jpg"

 

so try this

<?php

$X = split("/",$row[cover]);
echo "<td><img src=".$X[0]."tb_".$X[1]."></td>";

?>

 

 

if this fails can you also post the results of a

<?php

print_r($row[cover]);

?>

Link to comment
Share on other sites

Hi MadTechie, Should the code be included in the while loop:

 

Here is my entire code:

 

<?php
#specify the connection information
$db_server ="localhost";
$db_name = "comics";
$username = "root";
$password = NULL;        
#
#The following lines do not need to be edited
#
#make the connection.  If there is a problem, print out a helpful error message
$dbh = @mysql_connect($db_server,$username,$password) or die 
("Connection to $db_server with login '$username'/'$password' failed.");

if ($dbh = TRUE) {
echo "Connected!";
}

#select the database.  If the database is not found on the server, let us know
$db = @mysql_select_db($db_name) or die 
("Connection made. But database '$db_name' was not found.");

// Begin your table outside of the array
echo "<table width='100%' border='0' cellpadding='1' cellspacing='0'>
    <tr>
        <td width='110'><b></b></td>
    </tr>
<tr>
        <td width='110'><b></b></td>
	<td width='110'><b>WRITERS</b></td>
	<td width='110'><b>PUBLISHED</b></td>
    </tr>";

// Perform an statndard SQL query:
$res = mysql_query("SELECT cover, title, email, publish_date FROM comics ORDER BY title ASC") or die (mysql_error());


// Assuming $res holds the results from your query:
$class = 'even';
while ($row = mysql_fetch_assoc($res)) {
  $class = $class == 'even' ? 'odd' : 'even';
  echo "<tr class=\"$class\">\n";
  echo "<td><img src=$row[cover]></td>"; <---IMAGE BEING ECHOED
  echo "</tr>\n";
  echo "<tr class=\"$class\">\n";
  echo "<td>$row[title]</td>\n";
  echo "<td>$row[email]</td>\n";
  echo "<td>$row[publish_date]</td>\n";
  echo "</tr>\n";
}

?>

Link to comment
Share on other sites

Ahh ha

 

try this

<?php

#specify the connection information

$db_server ="localhost";

$db_name = "comics";

$username = "root";

$password = NULL;       

#

#The following lines do not need to be edited

#

#make the connection.  If there is a problem, print out a helpful error message

$dbh = @mysql_connect($db_server,$username,$password) or die

("Connection to $db_server with login '$username'/'$password' failed.");

 

if ($dbh = TRUE) {

echo "Connected!";

}

 

#select the database.  If the database is not found on the server, let us know

$db = @mysql_select_db($db_name) or die

("Connection made. But database '$db_name' was not found.");

 

// Begin your table outside of the array

echo "<table width='100%' border='0' cellpadding='1' cellspacing='0'>

    <tr>

        <td width='110'><b></b></td>

    </tr>

<tr>

        <td width='110'><b></b></td>

<td width='110'><b>WRITERS</b></td>

<td width='110'><b>PUBLISHED</b></td>

    </tr>";

 

// Perform an statndard SQL query:

$res = mysql_query("SELECT cover, title, email, publish_date FROM comics ORDER BY title ASC") or die (mysql_error());

 

 

// Assuming $res holds the results from your query:

$class = 'even';

while ($row = mysql_fetch_assoc($res)) {

  $class = $class == 'even' ? 'odd' : 'even';

  echo "<tr class=\"$class\">\n";

  //echo "<td><img src=$row[cover]></td>"; #<---IMAGE BEING ECHOED

 

  $X = split("/",$row['cover']);                                #<----NEW!!

  echo "<td><img src=".$X[0]."tb_".$X[1]."></td>";    #<----NEW!!

 

  echo "</tr>\n";

  echo "<tr class=\"$class\">\n";

  echo "<td>$row[title]</td>\n";

  echo "<td>$row</td>\n";

  echo "<td>$row[publish_date]</td>\n";

  echo "</tr>\n";

}

 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.