|
|
|
|
Like this code?
Show the author your appreciation.
|
|
| |
THIS IS NOT WORKING OUT OF THE BOX
this is a small bit of code i did the other day that i found very usefull and maybe you will too ;) $catsCnt is the result from count() ing a result from mysql_fetch_array. The first line of this file is where you define how many columns you want in your table.
you need to edit this code to fit your site and maybe even just remove the part marked important
| <?php
define('NUM_COLS', 2);
require_once ('../includes/config.inc');
if (!isset($_SESSION['user']['auth'])) {
header ("Location: http://www.nyaspdp.org/nyaspdp.php");
ob_end_clean();
exit();
} else {
// set the page title
$page_title = 'NYASPDP Browse Subjects';
include ('../includes/reg_header.htm');
// connect to the database
require_once ('../includes/dbconnect.php');
// START THE IMPORTANT STUFF
$query = "SELECT cat_id, cat_name FROM catg WHERE cat_name !='!INSTRUCTOR SELECT ONE'";
$result = @mysql_query($query) or die(mysql_error());
$cats = array();
while($cat=mysql_fetch_array($result)) {
array_push($cats, $cat);
}
$catsCnt = count($cats);
echo "\n<h1>Select A Subject</h1>";
echo "\n<table border='0' cellpadding='2' cellspacing='2' width='90%' align='center'>";
echo "\n<tr>";
for($x=0; $x < $catsCnt; $x++) {
if(($x+1) % NUM_COLS == 0) {
echo "<td class='tblData' width='".(100/NUM_COLS)."%' NOWRAP><a href='courses.php?sid=".$cats[$x]['cat_id']."' class='normal'>".$cats[$x]['cat_name']."</a></td></tr>";
if ($x!=($catsCnt-1)) echo "\n<tr>";
} else {
echo "<td class='tblData' width='".(100/NUM_COLS)."%' NOWRAP><a href='courses.php?sid=".$cats[$x]['cat_id']."' class='normal'>".$cats[$x]['cat_name']."</a></td>";
}
}
$numSpaces=$catsCnt%NUM_COLS;
if ($numSpaces!=0) {
for ($i=0;$i<=$numSpaces;$i++) {
echo "<td width='".(100/NUM_COLS)."%' NOWRAP> </td>";
}
echo "</tr>\n";
}
echo "\n</table>";
// END THE IMPORTANT STUFF
// Include the HTML footer.
include ('../includes/reg_footer.htm');
}
?> | | |
|
| Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Alternating background color for HTML table rows Categories : PHP, Databases, MySQL, HTML and PHP | | | A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL | | | Automatically printing the contents of an sql table in MySQL. Categories : MySQL, PHP, HTML and PHP, Databases | | | Pull Down Surfing - Surf on Change Categories : Java Script, MySQL, HTML and PHP, PHP, Databases | | | Dynamically generated pop-ups (Select items) Categories : PHP, HTML and PHP, MySQL, Databases | | | Creating thumbnails from MySQL Blobs online Categories : PHP, MySQL, Graphics, HTML and PHP, Databases | | | Record Set Paging with PHP (RSP) Categories : PHP, MySQL, Navigation, Databases, HTML and PHP | | | How to load a query result into a PHP Array Categories : PHP, Databases, Arrays, MySQL | | | Functions for loading images into a MySQL database and displaying them. Categories : Graphics, HTML and PHP, MySQL, PHP, Databases | | | Editing the virtusertable and sendmail.cw via PHP3.0 and Mysql Categories : MySQL, HTML and PHP, PHP, Databases | | | This function will populate the options in a drop down HTML select list
in a form from a database query.
Categories : MySQL, General SQL, PHP, HTML and PHP, Databases | | | How can i Preload a 'SELECT MULTIPLE'? Categories : HTML and PHP, PHP, MySQL, Databases | | | This simple function will take a few arguments and easily set a associative array for each column in a result from a MySQL query Categories : Databases, PHP, MySQL, Arrays | | | Paginating the mySQL data Categories : PHP, Algorithms, Databases, MySQL, HTML and PHP | |
|
|
|