473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

displaying a varying number of images.. in tables?!

Hey all.

I'm building a news system. I have a page to display all posts made to
category=$id, simple enough, now I wanna make an index page that looks
up all the categories from the news_topics table, displays their name,
a link to their page, and the image assigned to that category.

Here's the catch: I wanna put this in a table as the images are only a
few hundred pixels wide, so a flat list of each image would be boring
and inefficient. The thing is, we may add/remove news categories over
time, so how can I deal with this?

Would it really be easier to manually make this in HTML and change it
as/when we make modifications to the topics table?

-Matt

Jul 28 '05 #1
7 1490
Don't do this manually. You just need to have some code that will take
all of the images that need to be displayed in an array (say $images is
an array that contains the HTML code for all of the images) and have a
loop that goes through $images putting it in a table. It could have a
variable that keeps track of what column its on, and when it reaches a
certain number, go to the next row and reset the column counter
variable. When it reaches the end of $images, it just writes a few
"<td></td>" 's to fill the rest of that row, then closes the table.

Jul 29 '05 #2
I assume you've already connected to the mysql server, that you have
chosen database and that the connection is open... Then this should be
somehow what like what you need:

//Do query

$query = "SELECT * FROM `news_categories`";

$resultat = mysql_query($query);

//Start loop

while ($row= @mysql_fetch_array($resultat)) {

//Fetch info from the row
$cat_name = $row["cat_name"]; //fetch the name of the category
$cat_link = $row["cat_link"]; //fetch the link to the category
$cat_image = $row["cat_image"]; //fetch the image assigned to the
category

//Make the HTML

echo("<tr><td>$cat_name</td><td><a
href=\"$cat_link\">$cat_link</a></td><td><img src=\"$cat_img\"
alt=\"cat_name\"></td></tr>

$count++ ;
}

I have not tested it, but it should work...

Jul 29 '05 #3
doffer:

thanks for the code, but all it does it display a table of images one
by one in rows.. not what I need. I know theoretically what I need to
do (count the number of rows returned, and every three rows or so, echo
a "</td><td>") but I don't know how to actually code it.

Jul 29 '05 #4
I noticed that Message-ID:
<11**********************@g47g2000cwa.googlegroups .com> from
gu************@gmail.com contained the following:
thanks for the code, but all it does it display a table of images one
by one in rows.. not what I need. I know theoretically what I need to
do (count the number of rows returned, and every three rows or so, echo
a "</td><td>") but I don't know how to actually code it.


Probably not the most elegant way but...

$result=mysql_query($sql);

$row[0]="";
$columns=3;
$i=0;
$j=0;
print "<table>\n";
while($myrow=mysql_fetch_array($result)){

if($i==0 || $i%$columns!==0){
$row[$j].=" <td>".$myrow['Make']."</td>\n";
$i++;
}
else{
$j++;
$row[$j]="";
$row[$j].=" <td>".$myrow['Make']."$j</td>\n";
$i++;
}
}
while($i%$columns!==0){
$row[$j].=" <td>&nbsp;</td>\n";
$i++;
}
foreach($row as $value){
print " <tr>\n$value </tr>\n";
}
print"</table>";

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 29 '05 #5
I noticed that Message-ID: <r5********************************@4ax.com>
from Geoff Berrow contained the following:
Probably not the most elegant way but...

Forgot to get rid of the debugging

$result=mysql_query($sql);

$row[0]="";
$columns=3;
$i=0;
$j=0;
print "<table>\n";
while($myrow=mysql_fetch_array($result)){

if($i==0 || $i%$columns!==0){
$row[$j].=" <td>".$myrow['myfield']."</td>\n";
$i++;
}
else{
$j++;
$row[$j]="";
$row[$j].=" <td>".$myrow['myfield']."</td>\n";
$i++;
}
}
while($i%$columns!==0){
$row[$j].=" <td>&nbsp;</td>\n";
$i++;
}
foreach($row as $value){
print " <tr>\n$value </tr>\n";
}
print"</table>";
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 29 '05 #6
Thanks Geoff! After a few tweaks to display the images that worked
perfectly:
http://www.scenepointblank.com/matt/dev/news/

I need to credit you somewhere on this site when it's all done for all
the support, haha..

Jul 29 '05 #7
I noticed that Message-ID:
<11**********************@g49g2000cwa.googlegroups .com> from
gu************@gmail.com contained the following:
Thanks Geoff! After a few tweaks to display the images that worked
perfectly:
http://www.scenepointblank.com/matt/dev/news/

I need to credit you somewhere on this site when it's all done for all
the support, haha..


That would be nice :)

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 29 '05 #8

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

Similar topics

14
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
3
by: Dalan | last post by:
At first I was not certain what could cause Access 97 from displaying most jpeg images, but not all. After further testing, it seemed that all original images of less than 275 pixels per inch or...
0
by: Fronky | last post by:
Hope someone can help. I am still learning, so no laughing please. I am displaying records from a database using Response.Write(""); instead of the usual datagrid method. I am doing it this way...
4
by: Tim T | last post by:
Hi, I have a stored procedure executing a search and an asp.net page displaying the results in a datagrid. The datagrid has paging on it, I am using Visual Studio.NET and can't see any option...
13
by: Jose.M.Huerta | last post by:
I'm trying to display in a continuos form some *.jpg. I have a table with the file path, (a photo of a person). Display these photos in a single form is very easy, just using changing some...
1
by: David Lozzi | last post by:
Hello, I'm wondering whats the best method to use for displaying several photos' thumbnails. One method I know is to dynamically resize the photo at the time the page is loaded. What does this...
4
by: redpears007 | last post by:
Hi Again, Throwing this one out to you again as i am not getting anywhere and can find little to no information out there. I am currently displaying images (Jpegs) in access via the routine...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
5
by: Stepheno | last post by:
Hi, I am a recently converted Iseries (AS/400) RPG programmer trying to learn HTML/CSS/JavsScript all at the same time (not fun). My problem deals mostly with CSS. I will be reveiving a table,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.