473,586 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems outputting to a 3 column table in order to crate an image gallery

ste
Hi there,

I'm trying to query a MySQL database (containing image data) and to output
the results in a HTML table of 3 columns wide (and however many rows it
takes) in order to create a basic thumbnail gallery.

I can query and output the data as a single column table, but I'm having
problems filling up a 3 column table (with different images, looping
continuously until the end).

I would appreciate it if someone could take a look at the code below and
point me in the right direction or suggest any extra lines of code which
would finish the job?

The code below puts an image on each row, instead of filling up 3 columns on
each row with a different image.

I open this gallery by going to
mywebsite.com/gallery.php?ima getype=landscap e (i.e. to access the landscape
gallery).

Thank you for any help,

Ste
<?php
include("my_db_ login.inc");

$connection = mysql_connect($ host,$user,$pas sword) or die ("couldn't connect
to server");
$db = mysql_select_db ($database,$con nection) or die ("Couldn't select
database");

$title = "Gallery";
$query = "SELECT * FROM mydatabase WHERE imagetype =
\"{$_GET['imagetype']}\"";
$result = mysql_query($qu ery) or die ("Couldn't execute query.");

echo "<h2>$title </h2>";
echo "<table>";
echo "<tbody>";

while ($row = mysql_fetch_arr ay($result))

{
extract($row);
echo "<tr>";
echo "<td><img src=\"$imageloc ation\" />\n
</td>\n";
}

echo "</tr>";
echo "</table>\n";
?>
Apr 29 '06 #1
10 2228
Rik
Why don't I see the bumber three anywhere in the code? Have you tried making
it 3 rows? How?
But I'm in a generous mood tonight:
echo "\n<table>" ;
$i = 3;
while ($row = mysql_fetch_ass oc($result))
{
if($i==3) echo "\n\t<tr>";
echo "\n\t\t<td> <img src=\".$row['imagelocation']." /></td>";
$i--;
if($i==0) {
echo "\n\t<tr>";
$i = 3;
}
}
if($i!=3) echo "\n\t\t<td colspan=\"$i\"> </td>\n\t</tr>";
echo "\n</table>";

Grtz,
--
Rik Wasmus
Apr 29 '06 #2
ste

"Rik" <lu************ @hotmail.com> wrote in message
news:e2******** **@netlx020.civ .utwente.nl...
Why don't I see the bumber three anywhere in the code? Have you tried
making
it 3 rows? How?
But I'm in a generous mood tonight:
echo "\n<table>" ;
$i = 3;
while ($row = mysql_fetch_ass oc($result))
{
if($i==3) echo "\n\t<tr>";
echo "\n\t\t<td> <img src=\".$row['imagelocation']." /></td>";
$i--;
if($i==0) {
echo "\n\t<tr>";
$i = 3;
}
}
if($i!=3) echo "\n\t\t<td colspan=\"$i\"> </td>\n\t</tr>";
echo "\n</table>";

Grtz,
--
Rik Wasmus


Hi Rik,

I had two main outcomes when trying to write the code for this - the one you
saw in my post (which posted 1 image per table row), and another one which
did post 3 images per row, but each row contain identical images (i.e. it
was just duplicating code, as opposed to inserting the next record/image).
As I've not yet grasped enough skills with PHP yet, and in my frustration of
nearly seeing what I was hoping for, I completely overlooked the fact that
the number 3 should be in my code at some point! :-S

Thank you for being in such a generous mood and posting the above code, it's
appreciated! :-)

When I first ran it, I had a message saying "Parse error: parse error,
unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or
T_NUM_STRING" on the line containing the code 'imagelocation' above.

I googled this message and found the solution was to remove the apostrophe's
surrounding ['imagelocation'], and this now works great! I also inserted a
\ in front of the quotation mark after imagelocation, but I'm not sure if
this made any difference at all.

Thanks again, I'd have *never* have gotten there with this assistance.

Ste
Apr 30 '06 #3
Rik
ste wrote:
echo "\n\t\t<td> <img src=\".$row['imagelocation']." /></td>";

When I first ran it, I had a message saying "Parse error: parse error,
unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or
T_VARIABLE or T_NUM_STRING" on the line containing the code
'imagelocation' above.

It should offcourse be:
echo "\n\t\t<td> <img src=\"".$row['imagelocation']."\" /></td>";

--
Rik Wasmus
Apr 30 '06 #4
ste

"Rik" <lu************ @hotmail.com> wrote in message
news:e3******** **@netlx020.civ .utwente.nl...
ste wrote:
echo "\n\t\t<td> <img src=\".$row['imagelocation']." /></td>";

When I first ran it, I had a message saying "Parse error: parse error,
unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or
T_VARIABLE or T_NUM_STRING" on the line containing the code
'imagelocation' above.

It should offcourse be:
echo "\n\t\t<td> <img src=\"".$row['imagelocation']."\" /></td>";

--
Rik Wasmus

Thanks Rik, I've now updated it.

Now when I open this page: mywebsite.com/gallery.php?ima getype=landscap e
it opens all the images from my database which are tagged with the category
of landscape.

Likewise, going to the url: mywebsite.com/gallery.php?ima getype=portrait
it opens all the images from my database which are tagged with the category
of portrait.

Is there a way to open the gallery showing ALL pictures, without having to
re-write the sql query? i.e. is there a tag I can enter in a URL which
displays images where the imagetype could literally be anything?
mywebsite.com/gallery.php?ima getype=anything

If there is such a term, I haven't been able to find it, but thought I'd ask
anyway in case you knew otherwise.

Thanks,

Ste
Apr 30 '06 #5
Rik
ste wrote:
Likewise, going to the url:
mywebsite.com/gallery.php?ima getype=portrait
it opens all the images from my database which are tagged with the
category of portrait.

Is there a way to open the gallery showing ALL pictures, without
having to re-write the sql query? i.e. is there a tag I can enter in
a URL which displays images where the imagetype could literally be
anything? mywebsite.com/gallery.php?ima getype=anything

just don't set the imagetype, so the url would be mywebsite.com/gallery.php,
and use this code:

//create database $connection

if(get_magic_qu otes_gpc()){
$_GET['imagetype'] = stripslashes($_ GET['imagetype']);
}
$imagetype = mysql_real_esca pe_string( $_GET['imagetype'], $connection);
$where = (isset($_GET['imagetype'])) ? "WHERE imagetype =
'".$_GET['imagetype']."'" : '';
$query = "SELECT * FROM mydatabase ".$where;

Grtz,
--
Rik Wasmus
Apr 30 '06 #6
Rik
Rik wrote:
$where = (isset($_GET['imagetype'])) ? "WHERE imagetype =

'".$_GET['imagetype']."'" : '';

Should be:
$where = (isset($_GET['imagetype'])) ? "WHERE imagetype = '".$imagetype." '"
: '';
--
Rik Wasmus
Apr 30 '06 #7
ste

"Rik" <lu************ @hotmail.com> wrote in message
news:e3******** **@netlx020.civ .utwente.nl...
Rik wrote:
$where = (isset($_GET['imagetype'])) ? "WHERE imagetype =

'".$_GET['imagetype']."'" : '';

Should be:
$where = (isset($_GET['imagetype'])) ? "WHERE imagetype =
'".$imagetype." '"
: '';
--
Rik Wasmus

Thanks for this Rik. If I'm understanding this correctly, adding the above
code to the existing gallery script will allow all images in the database to
be displayed when a user opens the gallery.php (as it was currently
displaying a blank page), or, it can still be used to open specific
galleries when it is used with the extension of
gallery.php?ima getype=landscap e

I have added your code to the existing code, and also removed the previous
line of code which contained the old $query line.

Unfortunately (and I've probably done something wrong here), the code below
(which is how I've incorporated your latest piece of code into the existing
code) doesn't quite do this - when I open gallery.php, it's not opening all
the images, but is instead opening all images which have a blank value for
imagetype (which would normally be none, but I've just added an image to the
database to test, which is why I know this is what's happening). When I
open gallery.php?ima getype=landscap e, this works as it did previously so no
problems here. Have I added it correctly?

<?php
include("my_db_ login.inc");

$connection = mysql_connect($ host,$user,$pas sword) or die ("couldn't connect
to server");
$db = mysql_select_db ($database,$con nection) or die ("Couldn't select
database");

if(get_magic_qu otes_gpc()){
$_GET['imagetype'] = stripslashes($_ GET['imagetype']);
}

$imagetype = mysql_real_esca pe_string( $_GET['imagetype'], $connection);
$where = (isset($_GET['imagetype'])) ? "WHERE imagetype = '".$imagetype." '":
'';
$query = "SELECT * FROM mydatabase ".$where;
$result = mysql_query($qu ery) or die ("Couldn't execute query.");

echo "\n<div id=\"content\"> ";
echo "\n<h2>Samp le Gallery</h2>";
echo "\n<table id=\"thumbgalle ry\" cellSpacing=\"0 \" cellPadding=\"1 0\"
width=\"400\" border=\"0\">";
echo "\n<tbody>" ;
$i = 3;
while ($row = mysql_fetch_ass oc($result))
{
if($i==3) echo "\n\t<tr>";
echo "\n\t\t<td valign=\"top\" width=\"113\" id=\"thumbs\">< img
src=\"".$row['imagelocation']."\" width=\"113\" border=\"0\" /><p
class=\"caption ref\">Ref: ".$row['imageid']."</p><p
class=\"caption \">".$row['imagecaption']."</p></td>";
$i--;
if($i==0) {
echo "\n\t<tr>";
$i = 3;
}
}
if($i!=3) echo "\n\t\t<td colspan=\"$i\"> </td>\n\t</tr>";
echo "\n</tbody>";
echo "\n</table>";

?>
Thanks,

Ste
Apr 30 '06 #8
Rik
The only thing I can think of is that the following code sets
$_GET['imagetype'], allthough it didn't previsously exist.

if(get_magic_qu otes_gpc()){
$_GET['imagetype'] = stripslashes($_ GET['imagetype']);
}

Try echoing your query, is should be "SELECT * FROM mydatabase" and nothing
more.
Else try:

$where = (isset($_GET['imagetype'])&&$_GET['imagetype']!='') ? "WHERE
imagetype = '".$imagetype." '":'';

Grtz,
--
Rik Wasmus
Apr 30 '06 #9
ste

"Rik" <lu************ @hotmail.com> wrote in message
news:e3******** **@netlx020.civ .utwente.nl...
The only thing I can think of is that the following code sets
$_GET['imagetype'], allthough it didn't previsously exist.

if(get_magic_qu otes_gpc()){
$_GET['imagetype'] = stripslashes($_ GET['imagetype']);
}

Try echoing your query, is should be "SELECT * FROM mydatabase" and
nothing
more.
Else try:

$where = (isset($_GET['imagetype'])&&$_GET['imagetype']!='') ? "WHERE
imagetype = '".$imagetype." '":'';

Grtz,
--
Rik Wasmus

Hi Rik,

I replaced the existing $where line with the one above as per your
suggestion, and this now works perfectly! :-)

Old: $where = (isset($_GET['imagetype'])) ? "WHERE imagetype =
'".$imagetype." '": '';
New: $where = (isset($_GET['imagetype'])&&$_GET['imagetype']!='') ? "WHERE
imagetype = '".$imagetype." '":'';

I wouldn't have a clue why one works and one doesn't (well, they both worked
of course, but 1st one returned only blank fields, and the 2nd one returned
all fields which is what I wanted), but I've got a few books to work through
now so I'll revisit this post in a few months (if I'm lucky!) and let you
know! :-)

Thanks for all your help Rik, it's appreciated.

Ste
May 1 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2091
by: Oliver | last post by:
Hi, I have a strange problem and I am not sure where to look for the core reason. I have a homepage in php which is working fine since ages and I have now a new server with a fresh Suse 9.1 installation and all apache + php modules installed (coming with Suse). My side is working allright apart from my image gallery which does not generate...
8
3792
by: CAFxX | last post by:
i'm writing a program that executes some calculations on a bitmap loaded in memory. these calculation ends up with pixel wth values far over 255, but i need them to be between 0 and 255 since i got to write them in a bmp file (in which RGB values are limited to 8 bits per channel). so i need to have them scaled down. first of all i find...
2
21342
by: me | last post by:
I would like to add an Identity to an existing column in a table using a stored procedure then add records to the table and then remove the identity after the records have been added or something similar. here is a rough idea of what the stored procedure should do. (I do not know the syntax to accomplish this can anyone help or explain this?...
2
2522
by: robert | last post by:
I've made a gallery site for an artist and it works well -- the gallery page has a central large image which is swapped when thumbnail images are clicked. I'm using Dreamweaver's "SwapImage" behavior. The problem is that this fails under certain versions of IE and possibly NN on PCs and Macs -- I haven't gotten my client to send me details of...
6
1951
by: ste | last post by:
Hi there, I'm just beginning to learn PHP and MySQL, but I'm finding it difficult! I wondered if someone could help me out with a problem I'm having, or at least point me in the right direction? I have setup a MySQL database which contains the following, though I would like to expand on this in the future with lots of extra fields: ...
2
1779
by: teddymeu | last post by:
Hi Guys, this is kinda complicated but ill do my best to explain. I have two tables. products and categories. Products holds product info and an image, its primary key is ProductID. Category table holds a category name and description and a primary key CategoryID. The producs table holds a Foreign key field called CategoryID which points to the...
4
10658
tjc0ol
by: tjc0ol | last post by:
Hi guys, I'm a newbie in php and I got error in my index.php which is: 1054 - Unknown column 'p.products_id' in 'on clause' select p.products_image, pd.products_name, p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status,...
4
2039
by: saunders1989 | last post by:
Hi, my goal is to create a website with an image gallery. i have about 6 buttons at the bottom of the page whcih when clicked will take you to a different album of photos. i have created the login page and the next step is to create the upload form to a database. these are the tables i am going to intened to use: TABLE: Gallery gID -...
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.