brown2005 Posted September 20, 2006 Share Posted September 20, 2006 hi....i want to take some results from the database sayapplesattackbobbrickboysetc, etc and display them likeAapples, attackBbob, boys, brickand so on based on the first letter and then in order...any ideas please? Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/ Share on other sites More sharing options...
shocker-z Posted September 20, 2006 Share Posted September 20, 2006 [code]$query = mysql_query("SELECT LEFT(field, 1) as 'first', field FROM table ORDER by first ASC");$letter='';while ($row=mysql_fetch_array($query)) { if ($row['first'] !== $letter) { $letter=$row['first']; echo "<B>$first</b><br>"; } if ($row['first'] == $letter) { echo "$row[field]<br>"; }}[/code]i beleave that should* work but hasn't been tested Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-95214 Share on other sites More sharing options...
HuggieBear Posted September 20, 2006 Share Posted September 20, 2006 [quote][code]$query = mysql_query("SLEECT LEFT(field, 1) as 'first', field FROM table ORDER by first ASC");[/code][/quote]Typo in SELECT...RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-95218 Share on other sites More sharing options...
shocker-z Posted September 20, 2006 Share Posted September 20, 2006 cheers huggie changed it :) Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-95221 Share on other sites More sharing options...
brown2005 Posted September 20, 2006 Author Share Posted September 20, 2006 $query = mysql_query("SELECT LEFT(topic_a, 1) as 'first', topic_a FROM A ORDER by first ASC");$letter='';while ($row=mysql_fetch_array($query)) { if ($row['first'] !== $letter) { $letter=$row['first']; echo "<B>$first</b><br>"; } if ($row['first'] == $letter) { echo "$row[topic_a]<br>"; } }i have used the above and get http://www.fantasy-comps.com/a.phpbut hasnt actually done what I wanted... i wanted the letter above it and then in the same row, and if fills up the row the next row....i.e.[b]A[/b]a, ab, ac, ad, ae, afag, ah, ai, aj[b]B[/b]bb, ba, bb, bc Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-95328 Share on other sites More sharing options...
brown2005 Posted September 21, 2006 Author Share Posted September 21, 2006 Hi, I was wondering if anyone knew if this is posisble at all? Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-95872 Share on other sites More sharing options...
brown2005 Posted September 28, 2006 Author Share Posted September 28, 2006 Hi, I was wondering if there was anyone at all out there that can possibly help with this? Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-100107 Share on other sites More sharing options...
Barand Posted September 28, 2006 Share Posted September 28, 2006 Do you mean[code]<?php$query = mysql_query("SELECT LEFT(topic_a, 1) as 'first', topic_a FROM A ORDER by topic_a");$letter='';while (list($first,$topic)=mysql_fetch_row($query)){ if ($first !== $letter) { $letter = $first; $count = 0; echo "<h3>" . strtoupper($first) . "</h3>"; } if (!$count) echo "$letter,"; echo " $topic"; $count++; if ($count%5 == 4) echo '<br>'; }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-100118 Share on other sites More sharing options...
brown2005 Posted September 28, 2006 Author Share Posted September 28, 2006 Hi, That is looking more like I want, but it needs a few adjustments, view [url=http://www.links-bid.com/1.php to]http://www.links-bid.com/1.php to[/url] and you will see.I want the letter moved from the start, not the bold one the one say like a, and then it should have a , after every topic.....Thanks for all your help Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-100126 Share on other sites More sharing options...
Barand Posted September 28, 2006 Share Posted September 28, 2006 [code]<?php$query = mysql_query("SELECT LEFT(topic_a, 1) as 'first', topic_a FROM A ORDER by topic_a");$letter='';while (list($first,$topic)=mysql_fetch_row($query)){ if ($first !== $letter) { $letter = $first; $count = 0; echo "<h3>" . strtoupper($first) . "</h3>"; } echo ($count) ? "," : ""; if ($count && $count%5 == 0) echo '<br>'; echo ($count) ? " $topic" : "$topic"; $count++;}?>[/code]EDIT: In your reply #4 you said you wanted letter on row[quote]i wanted the letter above it and then in the same row, [/quote] Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-100128 Share on other sites More sharing options...
brown2005 Posted September 28, 2006 Author Share Posted September 28, 2006 awesome... thanks very much.... Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-100131 Share on other sites More sharing options...
brown2005 Posted September 28, 2006 Author Share Posted September 28, 2006 echo"<table width='500' border='1' cellpadding='0' cellspacing='0'>"; echo" <tr> <td>"; echo ($count) ? "," : ""; if ($count && $count%10 == 0) echo '<br>'; echo ($count) ? " $topics_topic" : "$topics_topic"; $count++; echo"</td> </tr>"; echo"</table>";Hi i have tried putting the results in a table so they can be easily aligned and stuff, but it comes out all wrong.... check www.allinthissite.co.uk for what happens...is this the best way to do it in a table or would i use a div or something else? Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-100200 Share on other sites More sharing options...
HuggieBear Posted September 28, 2006 Share Posted September 28, 2006 Can you provide all of the code for this section, including the while loop...Also use code tags as it's easier to understand... [b][[/b][b]code][/b]My code goes here[b][[/b][b]/code][/b]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-100205 Share on other sites More sharing options...
brown2005 Posted September 28, 2006 Author Share Posted September 28, 2006 its ok i have worked it out..... i just put a table around the while loop.. thanks anyway Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-100211 Share on other sites More sharing options...
Barand Posted September 28, 2006 Share Posted September 28, 2006 or use css[code]<STYLE content="text/css">DIV.item { width: 100px; height: 20px; float: left; padding: 3px; text-align: left; font-size: 0.8em; font-weight: 300; border: 1px solid #EEE;}DIV.head { width: 500px; height: 40px; padding: 13px 3px ; text-align: left; font-size: 0.9em; font-weight: 600; margin-top: 15px;}BR { clear: both;}</STYLE><?phpinclude 'db2.php';define ("COLS", 5);$query = mysql_query("SELECT LEFT(topic_a, 1) as 'first', topic_a FROM A ORDER by topic_a");$letter='';while (list($first,$topic)=mysql_fetch_row($query)){ if ($first !== $letter) { $letter = $first; $count = 0; echo "<br/><DIV class='head'>" . strtoupper($first) . "</DIV>"; } if ($count && $count % COLS == 0) echo '<br>'; echo "<DIV class='item'>$topic</DIV>"; $count++;}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21385-help-with-layout-of-multiple-results-in-table-solved/#findComment-100315 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.