squiggerz Posted July 31, 2007 Share Posted July 31, 2007 It's late, I've tried about 100 queries through google and several here.. possibly I'm not searching for the right words? Anyway, here's an example of what I'm trying to achieve and have no idea where to start: http://www.viroqua-wisconsin.com/directory/default.asp?alpha=A On that page, the listings, they are pulled from the db obviously by the first letter of their name. Check. I can do this. How do you format the results like that? Like 10 in a column, then 10 more in another column, I guess if there are more than 30 on that page, a paging file will likely start a page numbering list of some sort. Anybody know how to get them in those 1x10 columns and is nice enough to share the wealth of knowledge?? SQ Quote Link to comment https://forums.phpfreaks.com/topic/62617-formatting-return-listings-from-mysql/ Share on other sites More sharing options...
Lumio Posted July 31, 2007 Share Posted July 31, 2007 I think you want to do that: <?php $sql = "SELECT `column1`, `column2` FROM `table` WHERE LEFT(`column2`, 1) LIKE 'A' LIMIT 0,10"; $res = mysql_query($sql); ?> Description: LEFT - Returns the first given signs (in this case the first sign of column2) = 'A' - If the mysql-function LEFT returns A... get it LIMIT 0,10 - Limit the rows start with the first row and stop with the 10th row. Quote Link to comment https://forums.phpfreaks.com/topic/62617-formatting-return-listings-from-mysql/#findComment-311701 Share on other sites More sharing options...
btherl Posted July 31, 2007 Share Posted July 31, 2007 The website you linked to uses two divs side by side for the columns. You can copy from their source to do it the same way. Is it the formatting you are more interested in, or the SQL to fetch the data? Quote Link to comment https://forums.phpfreaks.com/topic/62617-formatting-return-listings-from-mysql/#findComment-311702 Share on other sites More sharing options...
corbin Posted July 31, 2007 Share Posted July 31, 2007 In the case of divs, it's as simple as: <?php $link = mysql_connect(); mysql_select_db('yourdb', $link); $q = mysql_query("SELECT some, columns FROM table WHERE field LIKE 'a%'"); //lumio's query might be more effecient... not quite sure.... $i = 0; echo '<div>'; //open a div while($r = mysql_fetch_assoc($q)) { //echo some data or something if($i % 10 == 0) echo '</div><div>'; //if the remainder of $i/10 is 0 (aka 10 divides into it evenly) close the open div and open a new one $i++; } ?> echo '</div>'; //close the opened div Quote Link to comment https://forums.phpfreaks.com/topic/62617-formatting-return-listings-from-mysql/#findComment-311705 Share on other sites More sharing options...
squiggerz Posted July 31, 2007 Author Share Posted July 31, 2007 Definitely the formatting, I can grab from the db based on the alpha letter, but right now I've just got a while loop echo'ing the output: if ($a_results) { while ($a_row = mysql_fetch_array ($a_results, MYSQL_ASSOC)) { echo $a_row['biz_name']."<br>"; } } So I can return the data, I just want to be able to display it like they have it, in those nice 10 item columns. Just cant wrap my head around how to display it correctly.. Quote Link to comment https://forums.phpfreaks.com/topic/62617-formatting-return-listings-from-mysql/#findComment-311706 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.