470,833 Members | 1,224 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

It's my birthday... Please help me!

Aaaaaaaaaaaahhhhhhhhhhhhh

I can't figure out how to get the results to display in a multi-column
table, no matter how I try to format things I still get just one big
long line of images and links...

Ideally I'd like to break the results into a 4x5 table...

-----------------------------------------------------------------------

$result = mysql_query($sql, $conn) or die(mysql_error());
// go through each row in the result set and display data

while ($newArray = mysql_fetch_array($result)) {
// give a name to each of the fields
$id = $newArray['ProductID'];
$producturl = $newArray['ProductURL'];
$artist = $newArray['Artist'];
$price = $newArray['Price'];
$imageurl = $newArray['ImageURL'];
$title = $newArray['Title'];

//echo the results onscreen

echo "<table width=\"100%\"><tr><td align=\"center\">$id<br><a
href=\"$producturl\">$title</a><br><a href=\"$producturl\"><img
src=\"$imageurl\" border=\"0\"></a></td></tr></table>";
}
?>
Thanks to anyone and everyone that is willing to help.

Don Bedford.
p ------------------------------------------------------ 9
| _ _ |
| / *-* ( ... Play guitar? |
| ( | (O) |=|=|=|=|=(:::} http://www.donnybravos.com |
| \_ .-._( ''' Take a peek! |
| |
b--------------------------------------------------------d
Jul 20 '05 #1
8 1150
Webmaster wrote:
I can't figure out how to get the results to display in a multi-column
table, no matter how I try to format things I still get just one big
long line of images and links...


This is not a problem with MySQL, it is a problem with either html or
with php.

Happy birthday and next time, plese use better subject line.
Jul 20 '05 #2
Webmaster wrote:
I can't figure out how to get the results to display in a multi-column
table, no matter how I try to format things I still get just one big
long line of images and links...


This is not a problem with MySQL, it is a problem with either html or
with php.

Happy birthday and next time, plese use better subject line.
Jul 20 '05 #3
"Webmaster" <do*@donnybravos.com> wrote
Ideally I'd like to break the results into a 4x5 table...

Okay...you have six variables...but a 4X5 table has 20 spaces. Can you
explain a bit more about how you want the table to look?
Jul 20 '05 #4
"Webmaster" <do*@donnybravos.com> wrote
Ideally I'd like to break the results into a 4x5 table...

Okay...you have six variables...but a 4X5 table has 20 spaces. Can you
explain a bit more about how you want the table to look?
Jul 20 '05 #5
"Experienced but Undocumented" <e0*@removethis.toao.net> wrote in message
Okay...you have six variables...but a 4X5 table has 20 spaces. Can you
explain a bit more about how you want the table to look?


....

Thanks for your reply. I'll do my best to describe what I'd like to
do with the table...

I've got a database table set up so that each row represents a product
with each field containing information for the product.

I'm using the variables to produce the Image, link, description etc...
one product per cell in a table.

It's working... the image, link, and description etc show up, one
product per cell, but I can't figure out how to script it so that the
table isn't just 50 cells wide. I think what I need the script to do
is count each occurence of <td></td> and every 4 occurences have it
echo </tr><tr>?

But I haven't a clue as to how to go about doing that.

Am I even on the right track?

Thanks again!

Don Bedford.
<?php

// open connection
$conn = mysql_connect("localhost", "my_username", "pass");

// pick database
mysql_select_db("my_database",$conn);

// sql statement
$sql = "SELECT * FROM mytable";

// execute the sql statement
$result = mysql_query($sql, $conn) or die(mysql_error());

// go through each row in the result set and display data
while ($newArray = mysql_fetch_array($result))

{

// give a name to each of the fields
$producturl = $newArray['ProductURL'];
$imageurl = $newArray['ImageURL'];
$title = $newArray['Title'];

//echo the results onscreen
echo "<a href=\"$producturl\"><img
src=\"$imageurl\" border=\"0\"></a><br><a
href=\"$producturl\">$title</a></td><td>";

}

?>
</tr>
</table>
Jul 20 '05 #6
"Experienced but Undocumented" <e0*@removethis.toao.net> wrote in message
Okay...you have six variables...but a 4X5 table has 20 spaces. Can you
explain a bit more about how you want the table to look?


....

Thanks for your reply. I'll do my best to describe what I'd like to
do with the table...

I've got a database table set up so that each row represents a product
with each field containing information for the product.

I'm using the variables to produce the Image, link, description etc...
one product per cell in a table.

It's working... the image, link, and description etc show up, one
product per cell, but I can't figure out how to script it so that the
table isn't just 50 cells wide. I think what I need the script to do
is count each occurence of <td></td> and every 4 occurences have it
echo </tr><tr>?

But I haven't a clue as to how to go about doing that.

Am I even on the right track?

Thanks again!

Don Bedford.
<?php

// open connection
$conn = mysql_connect("localhost", "my_username", "pass");

// pick database
mysql_select_db("my_database",$conn);

// sql statement
$sql = "SELECT * FROM mytable";

// execute the sql statement
$result = mysql_query($sql, $conn) or die(mysql_error());

// go through each row in the result set and display data
while ($newArray = mysql_fetch_array($result))

{

// give a name to each of the fields
$producturl = $newArray['ProductURL'];
$imageurl = $newArray['ImageURL'];
$title = $newArray['Title'];

//echo the results onscreen
echo "<a href=\"$producturl\"><img
src=\"$imageurl\" border=\"0\"></a><br><a
href=\"$producturl\">$title</a></td><td>";

}

?>
</tr>
</table>
Jul 20 '05 #7
"Webmaster" <do*@donnybravos.com> wrote in message
news:df**************************@posting.google.c om...
It's working... the image, link, and description etc show up, one
product per cell, but I can't figure out how to script it so that the
table isn't just 50 cells wide. I think what I need the script to do
is count each occurence of <td></td> and every 4 occurences have it
echo </tr><tr>?

Okay, how about this:

<?PHP

$number_of_columns = 4;

$result = mysql_query($sql, $conn) or die(mysql_error());
// go through each row in the result set and display data

echo "<TABLE width='100%' cellspacing='0' cellpadding='0'>\n";
echo "<TR>\n";

$count = 0;

while ($newArray = mysql_fetch_array($result)) {
// give a name to each of the fields
$id = $newArray['ProductID'];
$producturl = $newArray['ProductURL'];
$artist = $newArray['Artist'];
$price = $newArray['Price'];
$imageurl = $newArray['ImageURL'];
$title = $newArray['Title'];

// echo the results onscreen
echo "<TD>$id<br><a href='$producturl'>$title</a><br><a
href='$producturl'><imgsrc='$imageurl' border='0'></a></TD>\n";

// Increment the count so we can see which column we're in
$count++;

// If it's the fourth column, start a new row
if ($count == $number_of_columns) {
echo "</TR><TR>\n";
$count = 0;
}

}
// Tidy up the last few cells
if ($count != 0) {
for ($i = 0; $i < $number_of_columns - $count; $i++) { echo
"<TD>&nbsp;</TD>"; }
}

echo "</TR></TABLE>";

?>
Jul 20 '05 #8
"Webmaster" <do*@donnybravos.com> wrote in message
news:df**************************@posting.google.c om...
It's working... the image, link, and description etc show up, one
product per cell, but I can't figure out how to script it so that the
table isn't just 50 cells wide. I think what I need the script to do
is count each occurence of <td></td> and every 4 occurences have it
echo </tr><tr>?

Okay, how about this:

<?PHP

$number_of_columns = 4;

$result = mysql_query($sql, $conn) or die(mysql_error());
// go through each row in the result set and display data

echo "<TABLE width='100%' cellspacing='0' cellpadding='0'>\n";
echo "<TR>\n";

$count = 0;

while ($newArray = mysql_fetch_array($result)) {
// give a name to each of the fields
$id = $newArray['ProductID'];
$producturl = $newArray['ProductURL'];
$artist = $newArray['Artist'];
$price = $newArray['Price'];
$imageurl = $newArray['ImageURL'];
$title = $newArray['Title'];

// echo the results onscreen
echo "<TD>$id<br><a href='$producturl'>$title</a><br><a
href='$producturl'><imgsrc='$imageurl' border='0'></a></TD>\n";

// Increment the count so we can see which column we're in
$count++;

// If it's the fourth column, start a new row
if ($count == $number_of_columns) {
echo "</TR><TR>\n";
$count = 0;
}

}
// Tidy up the last few cells
if ($count != 0) {
for ($i = 0; $i < $number_of_columns - $count; $i++) { echo
"<TD>&nbsp;</TD>"; }
}

echo "</TR></TABLE>";

?>
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

51 posts views Thread by Sandra | last post: by
1 post views Thread by Claude Alain | last post: by
5 posts views Thread by NomoreSpam4Me | last post: by
6 posts views Thread by kwangbok.kim | last post: by
1 post views Thread by TWX | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.