I have a mysql table with 19 fields.
The table name is: tbl_products
The fields are:
product_id, product1, product2, product3, product4, product5,
product6, product7, product8, product9, product10, product11,
product12, product13, product14, product15, product16, product17,
product18
product_id is the primary key and is an integer which auto
increments each time a new record is added to this table.
I want to know how to use a SELECT FROM statement to retrieve the
data and display the results in an HTML table on a Web page. The
data will need to appear in 3 columns based on the number of records
there are.
I have a script that will do it based on one field. I have no clue
how to do it with all of the fields I have in this table. Here's the
script I have that does it with one field. I'll post it on the board
and explain how it works so that everyone can use it, if needed.
---------------------------------------------------------------------
<?php
include("connectmeinc.php");
$connection = mysql_connect($host,$user,$password)
or die ("Couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
$query = "SELECT count(state) as state_n,state FROM states GROUP BY
state";
$result = mysql_query($query);
$numofitem = mysql_num_rows($result);
$half=(intval($numofitem)/3);
$n=0;
echo "<table align=\"left\" width=\"600\" border=\"0\"
cellpadding=\"10\" cellspacing=\"0\"><tr VALIGN=top> <td width=33%>";
while ($myrow = mysql_fetch_array($result))
{
extract($myrow);
echo "<font face='verdana' size='2'><b><a href='$myrow[state].php'
title='$state'>$myrow[state]</a></b> ($state_n)</font><br>";
$n=$n+1;
if ($n>=$half)
{
echo "</td> <td width=33%>";
$n=0;
}
}
echo "</td></tr></table>";
?>
---------------------------------------------------------------------
Can you please modify this code to do what I need done? It took me
forever just to find this code to be able to do it with one field! I
have searched endlessly with no avail while trying to do it with
multiple fields.
I'm thinking that somehow all of my fields can be stored into a
single variable, and then the variable can be used to "echo" the
results which will be displayed into 3 columns based on the number
of results. I still have no idea how to write the code to do this.
Thanks in advance for any help provided!
------------------------ Yahoo! Groups Sponsor --------------------~-->
Most low income homes are not online. Make a difference this holiday season!
http://us.click.yahoo.com/5UeCyC/BWHMAA/TtwFAA/CefplB/TM
--------------------------------------------------------------------~->
The php_mysql group is dedicated to learn more about the PHP/MySQL web database
possibilities through group learning.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php_mysql/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/