Jump to content

Inline image from existing database


hotmert

Recommended Posts

I have a gig listing database with a fields 'date', 'time', 'event, 'bands', 'info', 'pic', 'price'.  I have got the display looking good and out putting nicely. But it wont be truly complete until I can get the 'pic' to display.

 

'pic' will ultimately only ever be one per record and appx 130px x 130px so can be a blob (ooh) or point to a file. See img incl, 'pic' will go to the left of 'price'...border is just for definition and will not be in the final version.

 

All the examples assume the images are in a separate database and just position somewhere so I have found it difficult to find my way through all of these.

 

Plus I have used phpmyedit to create my admin form and will try to create a means of uploading eventually.

 

So help on image display would be very much appreciated.

 

Mike

 

//code

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View Details</title>

<style type="text/css">
.table-holder #even {
   padding: 5px;
   margin-bottom: 5px;
   font-family: Arial;   
}

.table-holder #even tr #price-colour, .table-holder #odd tr #price-colour {

       color: #D94D26;
       font-size: 20px;
       
}
.table-holder #even tr #bands-colour, .table-holder #odd tr #bands-colour {

       color: #FFFFFF;
       font-size: 20px;
       
}
.table-holder #even tr #event-colour, .table-holder #odd tr #event-colour {

       color: #D94D26;
       font-size: 20px;
       font-style:italic;
}
.table-holder #even tr #info-colour, .table-holder #odd tr #info-colour {

       color: #999999;
       font-size: 16px;
}
.table-holder #even {

       background-color: #333333;
       padding: 5px;
       margin-bottom: 5px;
}
.table-holder #details2 {
       background-color: #333333;
       padding: 5px;
       margin-bottom: 5px;
}
.table-holder #even tr td .title {

       color: #FF9;
       margin-right: 5px;
       font-size: 16px;
       
}
.table-holder #odd tr {
   background-color: #000000;
   font-family: Arial;
}
.table-holder #odd {
       background-color: #000000;

       padding: 5px;
       margin-bottom: 5px;
}
.table-holder #odd {
       background-color: #000000;

       padding: 5px;
       margin-bottom: 5px;
}
</style>
</head>
<body>

<form method = "POST" align="center">
<select name ="month">
<option>PICK A MONTH</option>
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
<option value="4">Apr</option>
<option value="5">May</option>
<option value="6">Jun</option>
<option value="7">Jul</option>
<option value="8">Aug</option>
<option value="9">Sept</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
<input type="submit" value="Rock on ! !"
</select>
</form>


<?php

#connect to MySQL
$link = mysql_connect('localhost', 'root', 'root'); 
if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
}

#select the database
$link = @mysql_select_db("gig_list1") or die("Could not select database");

//call user choice
$user_choy =$_REQUEST['month'];
echo "User selected <br>"; 


#create the SQL query which will output gig for month selected


$sql = "SELECT * FROM `listings` WHERE YEAR(`date`) = YEAR(NOW()) AND MONTH(`date`) = ('$user_choy') ORDER BY date" or die(mysql_error());

#execute the query
$link = @mysql_query($sql) or die("Could not execute SQL query");
?>
<div class="table-holder">
    <table width="100%" border="0" id="details">
<?
#loop through all records
$counter = 0;
while ($row = mysql_fetch_array($link)) 
{
   $rowclass = ($counter % 2 == 0) ? 'style="background-color: #333333"' : '';
   $tableclass = ($counter % 2 == 0) ? 'even' : 'odd';
   ?>
   <div class="table-holder">
   <table width="100%" border="1" padding="5" table height="100"id="<?=$tableclass;?>">

   <tr <?=$rowclass;?>>
       <td rowspan="3" valign="top "width="100" id="event-colour" align="left" style="border-right:2px solid black"><? echo date("D j", strtotime( $row["date"])); ?></td>
      
       <td width="7%" valign="top " id="event-colour" align="left"><? echo $row["time"]; ?></td>
      
       <td align="left" valign="top " align="left" id="event-colour"><? echo $row["event"]; ?></td>

      <td rowspan="3" width="12%"><? echo $row["pic"]; ?></td>

      <td width="10%" valign="top "margin="10px"style="border-left:2px solid black" rowspan="3" align="center" id="price-colour"><? echo $row["price"]; ?></td>
      
   </tr>
   <tr <?=$rowclass;?>>
       <td colspan="2" id="bands-colour"> <? echo $row["bands"]; ?></td>
      
   </tr>
   
   <tr <?=$rowclass;?>>
       <td colspan="2" id="info-colour"><? echo $row["info"]; ?></td>
      
   </tr>
   </table>
   </div>
   <?
   $counter++;
}
?>
    </table>
   
</div>


</body>
</html>

 

MOD EDIT: code tags added.

 

[attachment deleted by admin]

Link to comment
Share on other sites

I really don't see what the problem is, if you have a filed called 'pic' where you store the image name (or name and path), simply display it with everything else.

for the purpose of this example, I'll assume you are only storing the image name in the database and that you have a folder called 'bandImages' (or whatever)

 

change

<? echo $row["pic"]; ?>

for this:

<img src="bandImages/<? echo $row["pic"]; ?>">

 

hope this helps

Link to comment
Share on other sites

Webstyle, thank you, yes it did help. I obviously kept getting the syntax wrong on that. 

 

The image now works however the rows which contain no pic display the broken image link.  I have the field set to 'null' why is this?

Link to comment
Share on other sites

If there's nothing in the field, an empty <img> tag is still being echoed. It should instead only echo the tag if there is a filename in the field, or alternately if the field is empty use a default image.

 

echo !empty($row['pic']) ? "<img src=\"bandImages/{$row['pic']}\">" : '';

// OR //

echo !empty($row['pic']) ? "<img src=\"bandImages/{$row['pic']}\">" : "<img src=\"bandImages/default_image.png\">";

Link to comment
Share on other sites

That did the trick but also added a "> into every 'pic' cell, no punn intended

 


<td width="130" rowspan="3" align="center" id="thumb"><img width="130" height="130"<? echo !empty($row['pic']) ? "<img src=\"js/images/{$row['pic']}\">" : ''; ?>"></td>

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.