[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

PHP Multi-Column output needed

Posted on 2007-11-27
6
Medium Priority
?
986 Views
Last Modified: 2013-12-12
At the moment I get a result set of 50 in a single column:

business 1
business 2
business 3

...
business 50

But I would prefer to show the output in 2 columns:

business 1    bussiness 2
business 3    business 4
 ...

How can this be done?

This is the code for the output from MySQL DB I'm using at the moment:

      <table style="width:339px; style="line-height:20px;">
            <?php

            $result = mysql_query("SELECT bizID,bizName,bizAddr,bizCity,bizState,bizZip,bizPhone FROM biz_cars WHERE bizState='$bizState' AND bizCity='$bizCity' AND bizLive='1' GROUP BY bizName LIMIT $offset,50");
            while($r=mysql_fetch_array($result))
            {
                  $bizID = $r['bizID'];
                  $bizName = $r['bizName'];
                  $bizAddr = $r['bizAddr'];
                  $bizZip = $r['bizZip'];
                  $bizPhone = $r['bizPhone'];

                  $bizNameLink = replaceForText($bizName);

                  echo '<tr><td><span class="bigger-text">' . $bizNameLink . '
                  <br />
                      <a href="'. $urlPrefix . 'profile/' . $bizID . '.html">'.$bizAddr. '</a><br> '.$bizCity.', '.$bizState.' '.$bizZip.' <br>
                  '.  $bizPhone.'<br>
                  
            
                  </tr></td></span>';

            }
            ?>
            </table>
0
Comment
Question by:seopti
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 15

Expert Comment

by:babuno5
ID: 20362645
try the following code
$i=0;
 while($r=mysql_fetch_array($result))
{
	$bizID = $r['bizID'];
	$bizName = $r['bizName'];
	$bizAddr = $r['bizAddr'];
	$bizZip = $r['bizZip'];
	$bizPhone = $r['bizPhone'];
 
	$bizNameLink = replaceForText($bizName);
	if($i%2 == 0)
	{
		echo '<tr>';
	}
	echo '<td><span class="bigger-text">' . $bizNameLink . '
	<br />
	  <a href="'. $urlPrefix . 'profile/' . $bizID . '.html">'.$bizAddr. '</a><br> '.$bizCity.', '.$bizState.' '.$bizZip.' <br>
	'.  $bizPhone.'<br>
 
 
	</td>';
		
	if($i%2 == 0)
	{
		echo '</tr>';
	}
	++$i;
}

Open in new window

0
 
LVL 28

Expert Comment

by:gamebits
ID: 20362666
0
 

Author Comment

by:seopti
ID: 20362771
babuno5: Thanks for the code, but it did nothing. Nothing has changed using the code.

gamebits: Your code looks good but I can't get it to work with my current snippet which you see above. I am not sure how to merge these 2 snippets together.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 15

Expert Comment

by:babuno5
ID: 20362804
i m not sure why it did not work can show the part of the code with the changes i mentioned
or else some demo where i can see it
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 2000 total points
ID: 20363119
Try this, and let me know if it works.
<table style="width:339px; style="line-height:20px;">
            <?php
			$counter=0;
            $result = mysql_query("SELECT bizID,bizName,bizAddr,bizCity,bizState,bizZip,bizPhone FROM biz_cars WHERE bizState='$bizState' AND bizCity='$bizCity' AND bizLive='1' GROUP BY bizName LIMIT $offset,50");
            while($r=mysql_fetch_array($result))
            {
                  $bizID = $r['bizID'];
                  $bizName = $r['bizName'];
                  $bizAddr = $r['bizAddr'];
                  $bizZip = $r['bizZip'];
                  $bizPhone = $r['bizPhone'];
 
                  $bizNameLink = replaceForText($bizName);
                  
                  if($counter==0)
                  {
				  	echo "<tr>";
                  }
                  echo '<td><span class="bigger-text">' . $bizNameLink . '
                  <br />
                      <a href="'. $urlPrefix . 'profile/' . $bizID . '.html">'.$bizAddr. '</a><br> '.$bizCity.', '.$bizState.' '.$bizZip.' <br>
                  '.  $bizPhone.'<br>
                  </span></td>';
                  
                  if($counter==1)
                  {
                  	echo "</tr>";
                  	$counter = 0;
                  	continue;
                  }
				  $counter++;
            }
            ?>
</table>

Open in new window

0
 
LVL 7

Expert Comment

by:dttri
ID: 20363165
Hi,
I don't think this is a valid SQL statement:

"SELECT bizID,bizName,bizAddr,bizCity,bizState,bizZip,bizPhone FROM biz_cars WHERE bizState='$bizState' AND bizCity='$bizCity' AND bizLive='1' GROUP BY bizName LIMIT $offset,50"

Because when you use "GROUP BY bizName" then all fields in the SELECT (except bizName) must be in aggregate function.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question