Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9278405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:21:37+00:00 2026-06-18T17:21:37+00:00

Have a table with a list of items in each row concat together in

  • 0

Have a table with a list of items in each row concat together in a PHP select.

Test image of what I have at the moment.Current Table

As seen the job description, price each and quantity columns have different items concat together with a line break in between each item. The problem I have now found is that if a job description is to long it goes onto the next line mucking up being in line with the price each and quantity columns.

I have tried numerous nested tables, but all end up being to messy and spoiling the odd even CSS I have at the moment. So I keep coming back to the code below.

My select:

"SELECT DATE_FORMAT(`$quotedate`, '%d-%m-%Y') AS `$quotedate`, `$quoteno`, 
   `$customer`, `$contactname`, CONCAT_WS('\r\r', `$jobdescription1`, 
   `$jobdescription2`, `$jobdescription3`, `$jobdescription4`, `$jobdescription5`,
   `$jobdescription6`, `$jobdescription7`, `$jobdescription8`, `$jobdescription9`,
   `$jobdescription10`) AS `Job Description`, 
    CONCAT_WS('\r\r £', concat('£', `$priceeach1`), `$priceeach2`, `$priceeach3`, 
   `$priceeach4`, `$priceeach5`, `$priceeach6`, `$priceeach7`, `$priceeach8`, 
   `$priceeach9`, `$priceeach10`) AS `Price Each`, 
   CONCAT_WS('\r\r', `$quantity1`, `$quantity2`, `$quantity3`, `$quantity4`,
   `$quantity5`, `$quantity6`, `$quantity7`, `$quantity8`, `$quantity9`, `$quantity10`) 
   AS`Quantity`  
FROM {$table} 
WHERE `$status`=0 $search ORDER BY {$table}.`$quotedate` asc";

And table:

echo "<table id=\"quote_table\"><tr>";
for($i=0; $i<$fields_num; $i++){
$field = mysql_fetch_field($result);
echo "<th>{$field->name}</th>";
}
echo "</tr>";

while($row = mysql_fetch_row($result)){
echo "<tr id=\"data\">";

foreach($row as $cell)
echo nl2br ("<td>$cell</td>");

echo "</tr>";
}

Does anyone have any ideas how I could get around this.
Thanks

Solution
I used a slightly modified version of bmewsing’s answer.
So I used a select with no formatting. Then put it in a table with the following:

while($row = mysql_fetch_array($result))
{
BuildRow($row[$quotedate], $row[$quoteno], $row[$customer], $row[$contactname], 
       $row[$jobdescription1], "£" . $row[$priceeach1], $row[$quantity1]);

if($row[$jobdescription2]){ BuildRow2("", "", "", "", $row[$jobdescription2], "£" . $row[$priceeach2], $row[$quantity2]);}
if($row[$jobdescription3]){ BuildRow2("", "", "", "", $row[$jobdescription3], "£" . $row[$priceeach3], $row[$quantity3]);}
if($row[$jobdescription4]){ BuildRow2("", "", "", "", $row[$jobdescription4], "£" . $row[$priceeach4], $row[$quantity4]);}
if($row[$jobdescription5]){ BuildRow2("", "", "", "", $row[$jobdescription5], "£" . $row[$priceeach5], $row[$quantity5]);}
if($row[$jobdescription6]){ BuildRow2("", "", "", "", $row[$jobdescription6], "£" . $row[$priceeach6], $row[$quantity6]);}
if($row[$jobdescription7]){ BuildRow2("", "", "", "", $row[$jobdescription7], "£" . $row[$priceeach7], $row[$quantity7]);}
if($row[$jobdescription8]){ BuildRow2("", "", "", "", $row[$jobdescription8], "£" . $row[$priceeach8], $row[$quantity8]);}
if($row[$jobdescription9]){ BuildRow2("", "", "", "", $row[$jobdescription9], "£" . $row[$priceeach9], $row[$quantity9]);}
if($row[$jobdescription10]){ BuildRow2("", "", "", "", $row[$jobdescription10], "£" . $row[$priceeach10], $row[$quantity10]);}

}

function BuildRow($qdate, $qno, $cust, $cname, $jobdesc, $priceea, $qty){

if($qdate || $qno || $cust || $cname || $jobdesc || $priceea || $qty) {
echo "<tr class=\"top\">";
echo "<td>$qdate</td>";
echo "<td>$qno</td>";
echo "<td>$cust</td>";
echo "<td>$cname</td>";
echo "<td>$jobdesc</td>";
echo "<td>$priceea</td>";
echo "<td>$qty</td>";
echo "<tr/>";
}
}
function BuildRow2($qdate2, $qno2, $cust2, $cname2, $jobdesc2, $priceea2, $qty2){
if($qdate2 || $qno2 || $cust2 || $cname2 || $jobdesc2 || $priceea2 || $qty2) {
echo "<tr class=\"middle\">";
echo "<td>$qdate2</td>";
echo "<td>$qno2</td>";
echo "<td>$cust2</td>";
echo "<td>$cname2</td>";
echo "<td>$jobdesc2</td>";
echo "<td>$priceea2</td>";
echo "<td>$qty2</td>";
echo "<tr/>";
}
}  

Then used jQuery to add an ‘odd’ or ‘even’ class to the middle class depending on which the previous ‘top’ class has.

$(document).ready(function(){
$("#quote_table > tbody > tr.top:even").addClass("even");
$("#quote_table > tbody > tr.top:odd").addClass("odd");

$('.middle').each(function(){
var quote_class = $(this).prevUntil(".top").prev(".top").attr("class");
$(this).addClass(quote_class);
$(this).removeClass("top");
});

enter image description here

I then put:

$('tr.middle').hover(function(){
$(this).prevUntil(".top").nextUntil(".top").andSelf().prev().addClass("hover");},
function(){
$(this).prevUntil(".top").nextUntil(".top").andSelf().prev().removeClass("hover");
});

$('tr.top').hover(function(){
$(this).nextUntil(".top").andSelf().not('#add').addClass("hover");},
function(){
$(this).nextUntil(".top").andSelf().removeClass("hover");
});

So that each “block” would highlight when the mouse moved over part of it.

I only got the finished solution through trial and error, so there may be a better way.
But it works!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T17:21:39+00:00Added an answer on June 18, 2026 at 5:21 pm

    Don’t do formatting in your SQL query (no line breaks or concat). Select the individual attributes then build your table. A row for each description, price, qty set.

    for($i=0; $i<$fields_num; $i++){
    $field = mysql_fetch_field($result);
    echo "<th>{$field->name}</th>";
    }
    echo "</tr>";
    
    while($row = mysql_fetch_row($result)){
    
     //build date, number, customer, name and the first
     //job description, price and qty
     BuildRow($row[$quotedate], $row[$quoteno], $row[$customer], $row[$contactname], 
               $row[$jobdescription1], "£" . $row[$priceeach1], $row[$quantity1]);
     //now build a row/cells for each of the
     //additional description, price, qty in the result row.
     BuildRow("", "", "", "", $row[$jobdescription2], $row[$priceeach2], $row[$quantity2]);
     //etc...
    }
    
    function BuildRow($date, $num, $cust, $name, $descrip, $price, $qty){
     //don't build if empty
     if($date || $num || $cust || $name || $descrip || $price || $qty) {
       echo "<tr >";
       echo "<td>$date</td>";
       //etc...
       echo "</tr>";
     }
    }
    

    With some styling you should then be able to get it to look like a “block” for each quote.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of items in an html table. On each row (tr)
I have here a list of items in a table. Each item has a
I have created a TableView(Grouped Table View). And I can list the items in
I have a list on when items have been handed out. The table has
I have a large data table that contains a checkbox for each row. I
I have a table (foos) which is a list of Foos, one row per
I have a list containing list items which appear like a row in a
I have an html table, and on each row, i would like to add
I have a list of items that is refreshed daily where each item falls
I have a list of content items, each with a set width but different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.