0

I'm currently working on displaying some arrays using PHP and MySQL.

Simplified code looks like this:

$sql = "SELECT * FROM workorder";
$result = mysqli_query($dbc3,$sql);
$tryout_reports = array();
while ( $row = mysqli_fetch_assoc($result) ) {
   $tryout_reports[] = $row['file_name'] . "<br />";
}
$detail_report['tryout_reports'] = $tryout_reports;

I took a lot out of the SQL here, so if there's something wrong in there please don't mind. The SQL statement works fine.

The problem is it's being outputted with commas separating each value, and it's looking real bad.

The HTML on the page when run looks something like this:

File1.pdf <br>
","
File2.pdf <br>
","
etc..

Now, I've looked around quite a bit and i've tried the following:

ltrim()
rtrim()
explode()
str_replace()

I know rtrim works, but it doesn't remove the commas. I tried something like:

$tryout_reports[] = rtrim($row['file_name'],"pdf");

And it took the pdf out of the end of each one, but when I replace "pdf" with "," it does nothing.

Feeling really stuck, any help would be really appreciated!

Thanks

EDIT: Forgot to add, the page that uses this data and displays it on the page has this:

table.append("<tr><th>Tryout Reports </th><td>" + data[0].tryout_reports + "</td></tr>");

That is inside of a jQuery function which runs when a job number is clicked to display additional information.

9
  • 2
    So where's the code which outputs values? Commented Nov 4, 2014 at 19:21
  • It's on a separate page. Using TWIG framework. There isn't much there, very basic. I'll edit it into the question, though Commented Nov 4, 2014 at 19:24
  • 1
    That comma comes from javascript because you parse directly the array. You can use join: w3schools.com/jsref/jsref_join.asp Commented Nov 4, 2014 at 19:28
  • possible duplicate of PHP preg_split remove commas and trailing white-space Commented Nov 4, 2014 at 19:32
  • where is comma added ?. As per your code, I don't see the comma.. Commented Nov 4, 2014 at 19:37

1 Answer 1

1

That comma comes from javascript because you parse directly the array. You can use join: w3schools.com/jsref/jsref_join.asp

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.