Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Displaying images from a db?

Featured Replies

Hi guys,

 

I currently have a table displaying items from a mysql database. I would also like to add images to the table.

I have an images folder already in the same web directory as all my pages, containing the images I would like to display.

 

What code do I need to use to display these images in the table?

 

My code is currently as follows:

 

<?php

// Connect to MYSQL and Select database

$dbc = mysql_connect (*********,'****','*********') OR die('Could not connect to MySQL : ' . mysql_error() );

mysql_select_db ('cse') OR die('Could not select the database : ' .

mysql_error() );

// Perform SQL query

$query = "SELECT * FROM harrison_catergories WHERE Cat_id = 1";

$result = mysql_query ($query);

?>

</p>

<table width="700" border="1">

<tr>

<td width="120" height="32"><strong>Item</strong></td>

<td width="412"><strong>Description</strong></td>

<td width="70"><strong>Cost</strong></td>

<td width="70"><strong>Stock</strong></td>

<td width="70"><strong>Purchase</strong></td>

</tr>

<?php

while($row = mysql_fetch_array($result,MYSQL_ASSOC))

{

Echo "<tr><td>$row[item]</td><td>$row[Description]</td><td>$row[Cost]</td><td>$row[stock]</td><td><a href = 'purchase.php$row[Purchase]'>Buy</a></td></tr>\n";

}

mysql_close();

?>

 

Cheers guys, hope sum1 can help me out?

 

Jay

Hi this is how i did it when i first started to learn

 

<td><A href='message.php?id=$getthreads3[postid]'><img src='$getthreads3[image] 'width='100' height='100' border='0'>

 

you would want to remove the link and the post id info [image] been the the root of the image

 

so what i do is upload an image into a folder called upload or what ever you want to call it and while uploading the file put the root and name of the photo into the image colum so the image colum would be upload/photo1.jpg

 

hope it helps i dont have much time tonight but if you carnt get it work i ill write you a script so you can learn from it

 

good luck

  • Author
Hi this is how i did it when i first started to learn

 

<td><A href='message.php?id=$getthreads3[postid]'><img src='$getthreads3[image] 'width='100' height='100' border='0'>

 

you would want to remove the link and the post id info [image] been the the root of the image

 

so what i do is upload an image into a folder called upload or what ever you want to call it and while uploading the file put the root and name of the photo into the image colum so the image colum would be upload/photo1.jpg

 

hope it helps i dont have much time tonight but if you carnt get it work i ill write you a script so you can learn from it

 

good luck

 

Ok so if I wanted to to convert that code to work for an image called 'rugbyshirt' in a folder called 'images', stord in my website directory, how would I go about it?

 

Cheers, Jay????

Ok so if I wanted to to convert that code to work for an image called 'rugbyshirt' in a folder called 'images', stord in my website directory, how would I go about it?

 

Cheers, Jay????

this is an actual script i am using for a demo of how to extract images from a database

 

include"connect.php";

$query=mysql_query("SELECT * from fruit");

while ($result=mysql_fetch_array($query,MYSQL_ASSOC))

 

 

 

{

print "<table width=70%>";

print "<tr class='mainrow'><td width=25px><b>product number</b><br>$result

</td><td width=100px><img src='$result[image]' width='100' height='100'></td><td width=100px><b>Product Name</b><br>$result[name]</td><td width=70px><b>Price</b></br>$result[price]</td><td width=300px><b>Description</b><br>$result[description]</td></tr>";

}

print "</table>";

?>

you dond need to change the code just make sure you have a colum in mysql called images and that colum should be upload/rugbyshirt.jpg i am presuming its a jpg extension i can write you a full script if you have difficulty with it and then you can change things to suit your final script

I'm getting mixed messages here. Is the image stored in a database or a file on your servers file system?

 

To use an image in a table row you use something like

<td width="70"><strong><img src="images/rugbyshirt.jpg" alt="Rugby Shirt" /></strong></td>

  • Author
this is an actual script i am using for a demo of how to extract images from a database

 

include"connect.php";

$query=mysql_query("SELECT * from fruit");

while ($result=mysql_fetch_array($query,MYSQL_ASSOC))

 

 

 

{

print "<table width=70%>";

print "<tr class='mainrow'><td width=25px><b>product number</b><br>$result

</td><td width=100px><img src='$result[image]' width='100' height='100'></td><td width=100px><b>Product Name</b><br>$result[name]</td><td width=70px><b>Price</b></br>$result[price]</td><td width=300px><b>Description</b><br>$result[description]</td></tr>";

}

print "</table>";

?>

you dond need to change the code just make sure you have a colum in mysql called images and that colum should be upload/rugbyshirt.jpg i am presuming its a jpg extension i can write you a full script if you have difficulty with it and then you can change things to suit your final script

 

Brilliant, with a little tweeking, that worked.

Thanx heaps!!!

 

Jay.

  • Author
I'm getting mixed messages here. Is the image stored in a database or a file on your servers file system?

 

To use an image in a table row you use something like

<td width="70"><strong><img src="images/rugbyshirt.jpg" alt="Rugby Shirt" /></strong></td>

 

Yeah Gibbs you were right, thats pretty much what I came up with. Thanx.

I'm getting mixed messages here. Is the image stored in a database or a file on your servers file system?

 

To use an image in a table row you use something like

<td width="70"><strong><img src="images/rugbyshirt.jpg" alt="Rugby Shirt" /></strong></td>

No i store the image in folder called uploads then store the root of the folder in a varchar images is the name of the folder so you would have in mysql colum called image images/rugbyshirt.jpg i will write you a complet script and send it you

have you managed to get your images displayed i have a bit more time now i can write you a script and post it for you so that you can acctualy upload the file from your website form

  • Author
have you managed to get your images displayed i have a bit more time now i can write you a script and post it for you so that you can acctualy upload the file from your website form

 

Yeah got it working fine, thanx 4 all ur help.

 

I do however, have another query, do you know how i would go about sending a completed form in an email?

 

So once the submit button is pressed, the information filled in in the fields, will b emailed.

 

Cheers, Jay.

Yeah got it working fine, thanx 4 all ur help.

 

I do however, have another query, do you know how i would go about sending a completed form in an email?

 

So once the submit button is pressed, the information filled in in the fields, will b emailed.

 

Cheers, Jay.

This is Jems try the link if its not what ya after let me know

 

http://www.jemjabella.co.uk/scripts/free-php-mail-form

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.