The table layout didn't come out quite right once I posted the code. Hopefully, you guys and gals get the idea. If you were to use the code exactly as I have posted it, your table would come out with three rows and three columns. Hope this helps!
--- In [email protected], "wrwatson2003" <[EMAIL PROTECTED]> wrote: > > I found this script awhile back and thought you guys and gals may > want to use it at one time or another. > > I have modified this script to make it work for what I needed it > to do at the time, so you will have to modify it to suit your needs > (or just ask me or one of our other members to help!). For instance, > on thing I did that may be a little different than how some of you > may code your pages, instead of putting my "database connection" > code directly into this script, I am using an include file > ("connectmeinc.php") to store that information. > > As the script is set up now, it will allow you to arrange your > search results on a Web page into three columns. The 3 columns are > created on your "Results" Web page based on the number of records > there are in your table for one specific field. In this case, I am > using a field name called, "state". > > So, let's just say for example that you have a table > called, "tbl_states" and a field name called, "state" with a total > of 85 records. Out of those 85 records let's pretend that you have > information on users from only 8 different states. Now, with this > script you can make your search results appear on your "Results" > page like the example below. Let's pretend that you have the > following 8 states in your table: > > Alaska, California, Utah, Texas, Iowa, New York, Georgia, Florida > > Instead of making your displayed results (e.g. the states) appear as > shown above (linear, separated with commas), you can make your > results appear in columns like this: > > +-----------------+-----------------+-----------------+ > + Alaska (5) + Georgia (14) + Texas (23) + > +-----------------+-----------------+-----------------+ > + California (11) + Iowa (8) + Utah (4) + > +-----------------+-----------------+-----------------+ > + Florida (22) + New York (9) + > +-----------------+-----------------+ > > The numbers next to the states are the number of total records for > that state. You can display the total number of records for each > state by using the identifier "state_n". Notice where it appears in > the SELECT FROM query and then down in the HTML portion of the code. > > Also, pay close attention to the line of code that has this: > > $half=(intval($numofitem)/3); > > This line of code is set to display the results in three columns. To > change the number of columns you want your results to display in, > just change the number "3" to whatever number you wish. > > Here's the script. Enjoy! > > > <?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 tbl_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>"; > > ?> > ------------------------ 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/
