473,698 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

putting database results in a 5x1 table

I have a db of tens of thousands of entries. It's not too hard to pull
all the entries and build a table that displays them one at a time, but
in my case, that will be a huge waste of space. What I want to do is
put one record in each of the columns. I thinks it's possible to do
because I have seen very elaborate thumbnail gallery scripts to do this.
I just want to be able to put two or three strings of text from each
record into each row, and a checkbox. Here's sample of what I mean:

<table width="76%" border="1" cellspacing="1" cellpadding="1" >
<tr>
<td>$record1Lin e1<br>$record1$ Line2<br>
<input type="checkbox" name="$record1c heckbox" value="checkbox "></td>
<td>$record2Lin e1<br>$record2$ Line2<br>
<input type="checkbox" name="$record2c heckbox" value="checkbox "></td>
<td>$record3Lin e1<br>$record3$ Line2<br>
<input type="checkbox" name="$record3c heckbox" value="checkbox "></td>
<td>$record4Lin e1<br>$record4$ Line2<br>
<input type="checkbox" name="$record3c heckbox" value="checkbox "></td>
<td>$record5Lin e1<br>$record5$ Line2<br>
<input type="checkbox" name="$record5c heckbox" value="checkbox "></td>
</tr>
</table>

I want to pull about 200 records at a time from the db and display as
described above. How can I tell php to take five records from my result
set and display above, then loop through the result set until I'm done?

Thanks much for any guidance you can offer.

Ed
Sep 27 '05 #1
3 1752
Eddie Biscomb wrote:
I have a db of tens of thousands of entries. It's not too hard to pull
all the entries and build a table that displays them one at a time, but
in my case, that will be a huge waste of space. What I want to do is
put one record in each of the columns. I thinks it's possible to do
because I have seen very elaborate thumbnail gallery scripts to do this.
I just want to be able to put two or three strings of text from each
record into each row, and a checkbox. Here's sample of what I mean:

<table width="76%" border="1" cellspacing="1" cellpadding="1" >
<tr>
<td>$record1Lin e1<br>$record1$ Line2<br>
<input type="checkbox" name="$record1c heckbox" value="checkbox "></td>
<td>$record2Lin e1<br>$record2$ Line2<br>
<input type="checkbox" name="$record2c heckbox" value="checkbox "></td>
<td>$record3Lin e1<br>$record3$ Line2<br>
<input type="checkbox" name="$record3c heckbox" value="checkbox "></td>
<td>$record4Lin e1<br>$record4$ Line2<br>
<input type="checkbox" name="$record3c heckbox" value="checkbox "></td>
<td>$record5Lin e1<br>$record5$ Line2<br>
<input type="checkbox" name="$record5c heckbox" value="checkbox "></td>
</tr>
</table>

I want to pull about 200 records at a time from the db and display as
described above. How can I tell php to take five records from my result
set and display above, then loop through the result set until I'm done?

Thanks much for any guidance you can offer.

Ed


Set $numRows to how many records you have retrieved total...

for($i=0;$i<$nu mRows;$i=$i+5){
echo '<tr>';
for($j=$i;$j<($ i+5);$j++){
$line1='record' .$j.'Line1';
$line2='record' .$j.'Line2';
$checkbox='reco rd'.$j.'checkbo x';
echo '<td>',${$line1 },'<br>',${$lin e2},'<br>',
${$checkbox},'</td>';
}
echo '</tr>',"\n";
}

Try it - maybe I'm just too tired, but it looks ok from here (not tested
of course)... That is assuming that you actually have the variable names
set up as you had indicated in that block of HTML...

I would be more inclined to have the SQL return 3 columns per row so I
could just use something like: $row[0], $row[1], $row[2] for the
variables...

--
Justin Koivisto, ZCE - ju****@koivi.co m
http://koivi.com
Sep 27 '05 #2
another idea even though its a bit messy would be...

if(($count_td == "1")OR($count_t d == "")){ echo "<tr>"; }

echo "<td>$conte nt</td>";

if($count_td == "5"){ echo "</tr>"; $count_td = "1"; }else{
$count_td++; }

Sep 27 '05 #3
Eddie Biscomb wrote:
I have a db of tens of thousands of entries. It's not too hard to pull .... I want to pull about 200 records at a time from the db and display as
described above. How can I tell php to take five records from my result
set and display above, then loop through the result set until I'm done?


This will stretch the last column to fill the missing space.

<?php
require_once ("HTML/Table.php");
$sample_data = array ("john", "fred", "bob", "willy", "angie",
"frank", "betty", "george", "wilma", "dexter",
"jack", "ziggy", "flo", "shrek", "gork", "nobody");

function build(&$input, $cols = 5) {
$t = new HTML_Table(arra y("border" => 1));
$t->setAutoGrow(tr ue);

$array_size = count($input);
$line = 0;

for ($offset = 0; $offset < $array_size; $offset = $offset + $cols) {
$row = array_splice($i nput, 0, $cols);
$row_size = count($row);
$t->addRow($row) ;
if ($row_size < 5) {
$t->setCellAttribu tes($line, $row_size - 1,
array("colspan" => 5 - $row_size +1));
}
$line++;
}
return $t;
}

$res =& build($sample_d ata);
$res->display();
?>

You can also remove the lines that handle the "stretch", and just add
the result of the splice. The non-existant cells will be handled by
setAutoGrow then.

/m
Sep 27 '05 #4

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

Similar topics

0
1402
by: EMiller | last post by:
Hello, I am encountering a development challenge here that seems to be stumping me. I am developing a C#/.NET application using an MSDE database. There is a particular field in a table that I need to accept a two-dimensional array of integers. When creating the database, I chose the SQL_Variant datatype for this column to which I will be writing the array.
3
1885
by: jaf893 | last post by:
I have a series of test results with each result consisiting of 10 test conditions, 5 location conditions and then 3 test results. The table looks a bit like this: (T = test condition, L = location condition, R = test results) T1 T2 .. T10 L1 L2 .. L5 R1 R2 R3 xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
3
2938
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news groups for years, I figure it's time for me to contribute a little bit back, maybe some people out there will find this useful. * Introduction This is a "how-to" style article, showing by example how to dynamically
0
1727
by: teju | last post by:
Hi all, I am trying to populate tree view from the database. Till two levels i can populate it fine but when it reaches third level it doesn't expand. Below is the code, it has been taken from the reference of micrososft Sub PopulateNode(ByVal sender As Object, ByVal e As TreeNodeEventArgs) ' Call the appropriate method to populate a node at a particular level. If e.Node.ChildNodes.Count = 0 Then Select Case...
12
3939
by: grace | last post by:
i am wondering why my database retrieval becomes too slow...we set up a new server (ubuntu, breezy badger) machine where we transferred all our files from the old server.. Our new server uses Asus p5pe-vm motherboard and an Intel Pentium D 3.0Ghz processor, compared to the old one where we uses asrock motherboard and AMD Duron. Both has the same version of mysql installed... To summarized, both machine has the same configuration except...
1
7546
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and having the sql statement dynamically built according to the input provided by the user. I have used the method described here hundreds of times it is quick and adaptive. I generally use a frames page for the search, in this way the search is maintained...
1
2359
by: Brit | last post by:
I have an ASP file that retrieves names from an Access database for 4 different categories of membership, which the visitor to the page selects (corporate, institutional, regular, or student). The DNS name is "cati", the names are specified in the "Last_names" field, and the categories are in the "categories" field. l want the results sorted in alphabetic order by last name. However, the results appear to be in a totally random,...
1
27100
Curtis Rutland
by: Curtis Rutland | last post by:
How To Use A Database In Your Program Part II This article is intended to extend Frinny’s excellent article: How to Use a Database in Your Program. Frinny’s article defines the basic concepts of using databases very well and is prerequisite reading for this article. Frinny’s article explains how to use a SQL Server in your program, but there are other databases as well. Some of them provide .NET connectors, but for those that don’t,...
5
1442
by: jaad | last post by:
I have built a Database to take care of everything a rental building requires: work orders, purchase orders, task scheduling and so on… it work great but wanted to make it more efficient. Here are some of the things I need to change and wanted to know if it is possible to do it in a way that would be bullet proof. I currently use the “Work Orders” portion of the database to create a record when a building resident requires work performed at...
0
8604
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9160
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7729
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4370
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3050
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
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.