Guest D1proball Posted March 27, 2006 Share Posted March 27, 2006 I need to sort my results so that It shows 3 results per row. I can Only get it to make one huge line down my page with 1 result per row. What I wantResult 1 | Result 2 | Result 3Result 4 | Result 5 | Result 6What I getResult 1Result 2Result 3Result 4Result 5Result 6 Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/ Share on other sites More sharing options...
azuka Posted March 27, 2006 Share Posted March 27, 2006 Can I see your code? Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/#findComment-21066 Share on other sites More sharing options...
Guest D1proball Posted March 27, 2006 Share Posted March 27, 2006 [code]<?include("connect.php");$query = "SELECT * FROM accessories";$result = mysql_query($query) or die("Error: " . mysql_error());print"";while($row = mysql_fetch_array($result)){ print" <table width=\"31%\" height=\"88\" border=\"1\"> <tr> <td width=\"6%\" rowspan=\"3\"><img src=\"/images/$row%5Bimage%5D.gif\" width=\"80\" height=\"80\"></td> <td width=\"94%\"><strong>Name</strong>: $row[name]</td> </tr> <tr> <td height=\"31\"><strong>Price</strong>: $row[price]</td> </tr> <tr> <td height=\"23\"><strong>Origin</strong>: $row[origin]</td> </tr></table>";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/#findComment-21073 Share on other sites More sharing options...
Guest D1proball Posted March 27, 2006 Share Posted March 27, 2006 can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/#findComment-21275 Share on other sites More sharing options...
freakus_maximus Posted March 27, 2006 Share Posted March 27, 2006 I have done this before, but at work now. Will respond later after finding a snippet that shows what you are looking for. Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/#findComment-21343 Share on other sites More sharing options...
Guest D1proball Posted March 28, 2006 Share Posted March 28, 2006 I thought for sure somebody could help by now :( Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/#findComment-21443 Share on other sites More sharing options...
freakus_maximus Posted March 28, 2006 Share Posted March 28, 2006 OK, probably the easiest way to explain this is to show you the html version:[code]<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1"> <tr> <td width="33%">first 1</td> <td width="33%">second1</td> <td width="34%">third1</td> </tr> <tr> <td width="33%">first2</td> <td width="33%">second2</td> <td width="34%">thirdd2</td> </tr></table>[/code]To do the same thing in php with some values pulled from mysql do this:[code]$result = mysql_query("SELECT first, second, third FROM tablename");$row = mysql_fetch_row($result);<?echo "<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">";while($row=mysql_fetch_row($result)){echo "<tr>"; //each tr tag is going to create a new rowecho "<td>".$row[0]."</td>"; //each td tag is going to create a new columnecho "<td>".$row[1]."</td>"; //the row[#] is going to pull in the value from that part of the arrayecho "<td>".$row[2]."</td>";echo "</tr>";//this will close the row off}echo "</table>";?>[/code]So as long as there are values in the query it will continue to create a new row with three columns. Obviously you can add an additional "echo "<td>".$row[#]."</td>";" if you needed to add another coolumn.Hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/#findComment-21444 Share on other sites More sharing options...
Guest D1proball Posted March 28, 2006 Share Posted March 28, 2006 This is what I'm doing now and I'm still getting the same results. You can check out my site here. [a href=\"http://www.acadvocates.com/itemsearch.php\" target=\"_blank\"]http://www.acadvocates.com/itemsearch.php[/a][code]print"<table align=center cellspacing=3 cellpadding=3 border=0>";while($row = mysql_fetch_array($result)){ print" <tr> <td width=\"94%\"><strong>Name</strong>: $row[name]</td> </tr> <tr> <td height=\"31\"><strong>Price</strong>: $row[price]</td> </tr> <tr> <td height=\"23\"><strong>Obtained from</strong>: $row[origin]</td> </tr>";}print"</table>";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/#findComment-21449 Share on other sites More sharing options...
freakus_maximus Posted March 28, 2006 Share Posted March 28, 2006 [!--quoteo(post=359145:date=Mar 27 2006, 11:31 PM:name=D1proball)--][div class=\'quotetop\']QUOTE(D1proball @ Mar 27 2006, 11:31 PM) [snapback]359145[/snapback][/div][div class=\'quotemain\'][!--quotec--]This is what I'm doing now and I'm still getting the same results. You can check out my site here. [a href=\"http://www.acadvocates.com/itemsearch.php\" target=\"_blank\"]http://www.acadvocates.com/itemsearch.php[/a][code]print"<table align=center cellspacing=3 cellpadding=3 border=0>";while($row = mysql_fetch_array($result)){ print" <tr> <td width=\"94%\"><strong>Name</strong>: $row[name]</td> </tr> <tr> <td height=\"31\"><strong>Price</strong>: $row[price]</td> </tr> <tr> <td height=\"23\"><strong>Obtained from</strong>: $row[origin]</td> </tr>";}print"</table>";[/code][/quote]I think you have <tr> tags where you dont want them. Try this:[code]print"<table align=center cellspacing=3 cellpadding=3 border=0>";while($row = mysql_fetch_array($result)){ print" <tr> <td width=\"94%\"><strong>Name</strong>: $row[name]</td> <td height=\"31\"><strong>Price</strong>: $row[price]</td> <td height=\"23\"><strong>Obtained from</strong>: $row[origin]</td> </tr>";}print"</table>";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/#findComment-21455 Share on other sites More sharing options...
Guest D1proball Posted March 28, 2006 Share Posted March 28, 2006 now it changed it to this [a href=\"http://www.acadvocates.com/itemsearch.php\" target=\"_blank\"]http://www.acadvocates.com/itemsearch.php[/a] Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/#findComment-21456 Share on other sites More sharing options...
sKunKbad Posted March 28, 2006 Share Posted March 28, 2006 Is that the output your were looking for? I'm working on a similar output right now, and being new to php I found the code will work perfectly for what I need to do, except that I will be using a CSS layout. Never really liked table layouts. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/#findComment-21457 Share on other sites More sharing options...
freakus_maximus Posted March 28, 2006 Share Posted March 28, 2006 [!--quoteo(post=359152:date=Mar 28 2006, 12:01 AM:name=D1proball)--][div class=\'quotetop\']QUOTE(D1proball @ Mar 28 2006, 12:01 AM) [snapback]359152[/snapback][/div][div class=\'quotemain\'][!--quotec--]now it changed it to this [a href=\"http://www.acadvocates.com/itemsearch.php\" target=\"_blank\"]http://www.acadvocates.com/itemsearch.php[/a][/quote]You may need to adjust the width% you have on the first column. It says it should take up 94% of the screen, which is why everything else is slammed over to the right like that. That would also cause the wrapping of some of the text also. Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/#findComment-21459 Share on other sites More sharing options...
Guest D1proball Posted March 28, 2006 Share Posted March 28, 2006 still isnt working this simple task has become annoying lol Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/#findComment-21465 Share on other sites More sharing options...
freakus_maximus Posted March 28, 2006 Share Posted March 28, 2006 [!--quoteo(post=359161:date=Mar 28 2006, 12:20 AM:name=D1proball)--][div class=\'quotetop\']QUOTE(D1proball @ Mar 28 2006, 12:20 AM) [snapback]359161[/snapback][/div][div class=\'quotemain\'][!--quotec--]still isnt working this simple task has become annoying lol[/quote]I looked at the html source for the page after as it is and it's missing the <table> tags. That is why all the data is just flooded across the screen now. Actually, I can see that everything except the <tr> and <td> tags are missing. There's no <html>, <body>, etc...tags.I manually inserted the table tags and the standard html tags and tried it with the source and that appears to work fine.Only other thing I see is that you have a comma appearing after each numeric value.Without seeing the php code I can't tell why the table tags are not in there or why the comma is appearing. Quote Link to comment https://forums.phpfreaks.com/topic/5896-sorting-mysql-results-into-tables/#findComment-21577 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.