iikon Posted December 9, 2010 Author Share Posted December 9, 2010 Look i have not meant no dis-respect to anyone here, Maq has tried, I am a stroke victim, i cannot comprehend, I dabble in a little html is all, I came here for a little help in making a multi coulmn list, i have seen so many different examples i do not know where to begin again, all of this code makes my head wanna pop off. I do appreciate the assistance, if you cannot help me, please advise me of someone that i can hire to do this for me. Quote Link to comment Share on other sites More sharing options...
litebearer Posted December 9, 2010 Share Posted December 9, 2010 Ok, in the spirit of this site AND this time of year, here is a very basic example of listing all your teams in 5 columns. This a VERY simple example of placing result output into columns. Try it as a simple test. Do NOT worry about making it 'look pretty' until you see how it works. You will need to modify it a bit to account for your table name and field names. It lists them in alpha order ACROSS the rows. <?php $max_columns = 5; /* set max columns for table */ $i = 0; /* initially set counter to use in starting and ending rows */ ?> <table border ="2"> <?PHP include('db.php'); /* make connection to database here */ $query = "Select * FROM teams ORDER BY team_name"; /* define query */ $result = mysql_query($query); /* execute query */ $total_cells = mysql_num_rows($result); /* count total cells to be displayed */ $total_rows = ceil($total_cells / $max_columns); /* calculate total rows needed */ $junk1 = $total_rows * $max_columns; /* calculate number of empty cells in last row */ $junk2 = $junk1 - $total_cells; if($junk2==0) { $last_row = "</tr>"; }else{ $j = 0; while($j<$junk2){ $last_row = $last_row . "<td></td>"; $j ++; } $last_row = $last_row . "</tr>"; } while($row = mysql_fetch_array($result)) { /* begin looping thru the results */ $team_name = $row['team_name']; if($i == 0){ echo "<tr>"; $i ++; } ?> <td><?PHP echo $team_name ?></td> <?PHP $i ++; if($i > $max_columns) { /* check if need to close row */ echo "</tr>"; $i=0; } } echo $last_row . "</table>"; /* clean up last row */ ?> Quote Link to comment Share on other sites More sharing options...
iikon Posted December 9, 2010 Author Share Posted December 9, 2010 Light Bearer thank you, when i first pulled it up, i seen 5 columns, then i added some of the code to come up with the results of my new code which i messed something up and i have no idea what to change, here is my new code <?php require_once("global.php"); $id = htmlentities($_GET['id']); $order = mysql_real_escape_string($_GET['order']); $team = mysql_query( "SELECT * FROM `teams` WHERE `id`='".$id."'"); $t = mysql_fetch_array($team); $team_title = mysql_real_escape_string($t['title']); $t_tag = $t['tag']; $user = mysql_query( "SELECT * FROM `users` WHERE `team`='".$id."' $order"); $max_columns = 5; /* set max columns for table */ $i = 0; /* initially set counter to use in starting and ending rows */ ?> <title><?php echo $team_title; ?></title> </head> <link href="http://tspclan.com/mkportal/templates/TSP/style.css" rel="stylesheet" type="text/css" /> <body> <div align="center"> <table width="80%" border ="2"> <?PHP $query = "Select * FROM `teams` ORDER BY `title` ASC"; /* define query */ $team_title = mysql_real_escape_string($t['title']); $result = mysql_query($query); /* execute query */ $total_cells = mysql_num_rows($result); /* count total cells to be displayed */ $total_rows = ceil($total_cells / $max_columns); /* calculate total rows needed */ $junk1 = $total_rows * $max_columns; /* calculate number of empty cells in last row */ $junk2 = $junk1 - $total_cells; if($junk2==0) { $last_row = "</tr>"; }else{ $j = 0; while($j<$junk2){ $last_row = $last_row . "<td></td>"; $j ++; } $last_row = $last_row . "</tr>"; } while($row = mysql_fetch_array($result)) { /* begin looping thru the results */ $team_name = $row['team']; if($i == 0){ echo "<tr>"; $i ++; } { $team2 = mysql_query( "SELECT * FROM `teams` ORDER BY `title` ASC "); ?> <?PHP while($t2 = mysql_fetch_array($team2)) { $t_name = "<a style='font-weight:bold;' href='SS.php?id=".$t2['id']."'>".$t2['title']."</a>"; echo "<tr><td align='center' valign='top' class='row1 b_t b_l' style='border-bottom:none; background-color:#333333;'>".$t_name."</td><td align='center' valign='top' class='row1 b_t b_l' style='font-weight:bold; color:#fff000; border-bottom:none; Background-color:#333333;'>".$t2['tag']."</td></tr>"; } $i ++; if($i > $max_columns) { /* check if need to close row */ echo "</tr>"; $i=0; } } } echo $last_row . "</table>"; /* clean up last row */ ?> this made it the list 5 times as long as it was before Working "live" link of this page http://www.tspclan.com/SS/columns.php Thank you, like i said i have 0 clue of why its not working Quote Link to comment Share on other sites More sharing options...
litebearer Posted December 9, 2010 Share Posted December 9, 2010 Development for we 'novices' can be a SLOW painful process. When making ANYTHING it is done one piece at a time IF we want to catch our mistakes easily and early. Personally, I do NO formating of output (colors, font, etc) until I know that they information I want to display is there, ready for me. Although there are 'shortcuts', because I am far from an expert, I ALWAYS use the long approach to things. It helps me understand what is happening and helps locate my errors. ie. In your revised code you have the following line { $team2 = mysql_query( "SELECT * FROM `teams` ORDER BY `title` ASC "); Why the Brace - { - ? simple things like unbalanced quotes, braces, parans etc, can make your scripts work improperly Quote Link to comment Share on other sites More sharing options...
iikon Posted December 9, 2010 Author Share Posted December 9, 2010 no idea but i just merely copied it over from my orig. page code ive removed it, same result Quote Link to comment Share on other sites More sharing options...
iikon Posted December 9, 2010 Author Share Posted December 9, 2010 and i have taken your suggestion by removing all the "style" out of it Quote Link to comment Share on other sites More sharing options...
Anti-Moronic Posted December 9, 2010 Share Posted December 9, 2010 Hi iikon, something else as well: Sometimes you will find not many replies or a sudden silence from people who were helping you before. It happens to me all the time. People can only spend so much time helping. What I've seen others do is post questions to other help forums also to increase the replies. Another great site for this is http://stackoverflow.com. Just another suggestion to increase the amount of help you get and response times. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.