Jump to content

Formatting Return Listings from mySQL


squiggerz

Recommended Posts

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.