0

When we are supposed to fetch some 200 database entries using php and display them in the page using html, what is the best way to do so. Right now i am doing like this<?php echo $variable1?;>,,,,<?php echo $variable200;?> and feel like its bit slow to load. Any alternative please?

model:

$query_str = "select *from table where sl_no='$report_id' and code='$code'";
$row=$query->row_array();
    return $row;

controller:

$reports=$this->patient_model->fetch_previous_reports($pat_lab_id);
    echo json_encode($reports);
4
  • 1
    Need more code to see exactly what you are doing. Commented Feb 24, 2016 at 13:01
  • 1
    fetch the value in array format. and list out Commented Feb 24, 2016 at 13:02
  • Use Foreach -- php.net/manual/en/control-structures.foreach.php to loop through the array values, so you have $var[0] ... $var[199] as an array of organised data Commented Feb 24, 2016 at 13:04
  • And use pagination. Divide data set into parts. Commented Feb 24, 2016 at 13:04

1 Answer 1

0

You can fetch all the variables and store it in a array. Refer to this question, How to store row/column of mysql data in array, on how to store MySQL values in array.

More information on array: http://www.w3schools.com/php/php_arrays.asp.

Then, echo all the values stored in the array:

foreach ($array as $item) {
    echo $item . '<br/>';
}
Sign up to request clarification or add additional context in comments.

2 Comments

echo implode('<br>', $array);
@MaximColesnic Yup, missed out line break, thanks :)

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.