By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,347 Members | 1,389 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,347 IT Pros & Developers. It's quick & easy.

html table trouble

P: n/a
I have a database with three columns. One is an atomic number, one is a
pic url, and the other is a description. What I'm having trouble doing
is putting the url in one table row and the description in another table
row right below it like this...
<tr<tdsome pic url</td<tdother pic url</td></tr>
<tr><tdsome descripts </td<tdother descript </td></tr>

whilest limiting the rows to about 10 cells each,,....

any ideas?

Aaron
Apr 26 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
_Skare_Krow_ napisaƂ(a):
I have a database with three columns. One is an atomic number, one is a
pic url, and the other is a description. What I'm having trouble doing
is putting the url in one table row and the description in another table
row right below it like this...
<tr<tdsome pic url</td<tdother pic url</td></tr>
<tr><tdsome descripts </td<tdother descript </td></tr>

whilest limiting the rows to about 10 cells each,,....

any ideas?

Aaron
The easiest way is to use CSS - div + float property.
<?php

$arr =array(
array("file1","desc1"),
array("file2","desc2"),
array("file3","desc3"),
array("file4","desc4"),
array("file5","desc5"),
array("file6","desc6"),
array("file7","desc7"),
);

define('TABLE_COLS',4);

print "<table>".PHP_EOL;
$i=1;
while(list($key,$row) = each($arr)) {
$tmp[$i]=$row;
if($i++==TABLE_COLS) {
print "<tr>";
for($j=1;$j<=TABLE_COLS;$j++) {
print "<td>".$tmp[$j][0]."</td>";
}
print "</tr>".PHP_EOL;
print "<tr>";
for($j=1;$j<=TABLE_COLS;$j++) {
print "<td>".$tmp[$j][1]."</td>";
}
print "</tr>".PHP_EOL;
$i=1;
}
}
if($i>1) {
print "<tr>";
for($j=1;$j<=TABLE_COLS;$j++) {
print "<td>".(($j<$i)?$tmp[$j][0]:"")."</td>";
}
print "</tr>".PHP_EOL;
print "<tr>";
for($j=1;$j<=TABLE_COLS;$j++) {
print "<td>".(($j<$i)?$tmp[$j][1]:"")."</td>";
}
print "</tr>".PHP_EOL;
}
print "</table>";

--
Wiktor Walc
http://phpfreelancer.net
Apr 26 '07 #2

P: n/a
_Skare_Krow_ wrote:
I have a database with three columns. One is an atomic number, one is a
pic url, and the other is a description. What I'm having trouble doing
is putting the url in one table row and the description in another table
row right below it like this...
<tr<tdsome pic url</td<tdother pic url</td></tr>
<tr><tdsome descripts </td<tdother descript </td></tr>

whilest limiting the rows to about 10 cells each,,....

any ideas?

Aaron
Hi, Aaron,

Two easy ways - as you go through the result set to get your url, save
the matching description in an array. Then when you're done with your
url's, you can go through the description array and get the values.

The other way is after going through the result set to get your url, use
mysql_data_seek() to reposition the internal pointer and go through the
result set a second time to get the descriptions.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 26 '07 #3

P: n/a
On Apr 26, 6:28 am, _Skare_Krow_ <petra2...@gmail.comwrote:
I have a database with three columns. One is an atomic number, one is a
pic url, and the other is a description. What I'm having trouble doing
is putting the url in one table row and the description in another table
row right below it like this...
<tr<tdsome pic url</td<tdother pic url</td></tr>
<tr><tdsome descripts </td<tdother descript </td></tr>

whilest limiting the rows to about 10 cells each,,....

any ideas?

Aaron
once you have your results in a 2d array, use 2 loops, one to create
the cells, which steps through the array echoing pics iterating by
one, the outer loop iterates by however many cells you used, if 10
then $i+=10, you could use array_shift with less complexity but it
might be slower.

you could use fluid (floating) css with a simple array and just set
the number of columns using css instead.

Apr 26 '07 #4

P: n/a
On Thu, 26 Apr 2007 00:28:45 -0500, in comp.lang.php _Skare_Krow_
<pe*******@gmail.com>
<nJ******************************@sysmatrix.netwro te:
>| I have a database with three columns. One is an atomic number, one is a
| pic url, and the other is a description. What I'm having trouble doing
| is putting the url in one table row and the description in another table
| row right below it like this...
| <tr<tdsome pic url</td<tdother pic url</td></tr>
| <tr><tdsome descripts </td<tdother descript </td></tr>
|
| whilest limiting the rows to about 10 cells each,,....
|
| any ideas?
|
| Aaron
<?php
//--- init record limit var
$start=0;

//--- open connection to db and table

//--- get page number from url/post var
//--- and update the $start var

//--- create the query
$sql = "SELECT * FROM table LIMIT {$start},{start + 10}";
//--- execute query
$row1=""; $row2="";
for($i=0; $i<count($result); $i++)
{
$row1 .= "<td><img src'".$result[$i]->pic_url."'</td>";
$row2 .= "<td>".$result[$i]->pic_desc."</td>";
}
?>

<table>
<tr><?php echo $row1;></tr>
<tr><?php echo $row2;></tr>
</table>
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Apr 26 '07 #5

P: n/a
Jeff North wrote:
On Thu, 26 Apr 2007 00:28:45 -0500, in comp.lang.php _Skare_Krow_
<pe*******@gmail.com>
<nJ******************************@sysmatrix.netwro te:
>| I have a database with three columns. One is an atomic number, one is a
| pic url, and the other is a description. What I'm having trouble doing
| is putting the url in one table row and the description in another table
| row right below it like this...
| <tr<tdsome pic url</td<tdother pic url</td></tr>
| <tr><tdsome descripts </td<tdother descript </td></tr>
|
| whilest limiting the rows to about 10 cells each,,....
|
| any ideas?
|
| Aaron

<?php
//--- init record limit var
$start=0;

//--- open connection to db and table

//--- get page number from url/post var
//--- and update the $start var

//--- create the query
$sql = "SELECT * FROM table LIMIT {$start},{start + 10}";
//--- execute query
$row1=""; $row2="";
for($i=0; $i<count($result); $i++)
{
$row1 .= "<td><img src'".$result[$i]->pic_url."'</td>";
$row2 .= "<td>".$result[$i]->pic_desc."</td>";
}
?>

<table>
<tr><?php echo $row1;></tr>
<tr><?php echo $row2;></tr>
</table>
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
thanks everyone.. i've got enough info to try out.. i will post back
with my success or failure :P

aaron
Apr 26 '07 #6

P: n/a
_Skare_Krow_ wrote:
I have a database with three columns. One is an atomic number, one is a
pic url, and the other is a description. What I'm having trouble doing
is putting the url in one table row and the description in another table
row right below it like this...
<tr<tdsome pic url</td<tdother pic url</td></tr>
<tr><tdsome descripts </td<tdother descript </td></tr>

whilest limiting the rows to about 10 cells each,,....

any ideas?

Aaron
Oh and you guys are so much nicer and more helpful than the javascript
group...

aaron
Apr 26 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.