How do I return a string that builds a new table row each time a function is called in PHP?

526

I have created a function in PHP that is supposed to "return a string that builds a new table row each time it is called" . I've tried searching for how to do this but I'm unsure. Can anyone provide assistance ? My code for the function that I built is below:

<?php
//Creating the function returnRow().
function returnRow($counter, $quantity) 
{
    $ticketprice = 50;

    if($quantity >= 300)
    {
        $ticketprice = 30;
    }
    else if ($quantity >= 200)
    {
        $ticketprice = 35;
    }
    else if ($quantity < 200)
    {
        $ticketprice = 50;
    }

    //The return statement will go here but I do not know how to create it.
   //it will return a new html table row.
}

?>
146

Answer

Solution:

You haven't indicated how many columns are in this table but literally just return the HTML string you want:

<?php
//Creating the function returnRow().
function returnRow($counter, $quantity) 
{
    $ticketprice = 50;

    if($quantity >= 300)
    {
        $ticketprice = 30;
    }
    else if ($quantity >= 200)
    {
        $ticketprice = 35;
    }
    else if ($quantity < 200)
    {
        $ticketprice = 50;
    }
//Example, I don't know what columns are actually present
   return "<tr><td>{$quantity}</td><td>{$ticketprice}</td></tr>";

}

?>

People are also looking for solutions to the problem: javascript - How to delay the .keyup() handler until the user stops typing?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.