Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to iterate arraylist in php
    primarykey
    data
    text
    <p><strong>What my code does:</strong> I am returning arraylist from a php method -->method name:- getSubjectInfo().<br> And in my (Index.php) page i am getting this arraylist values in a $results variable. <em>Here i am stuck how to iterate the arraylist values in the index.php page?.</em> </p> <p><strong>My Problem:</strong> How to iterate the arraylist ($results) in my index.php page? Please see my below mention code</p> <p>i have used <code>$results = $sub_info-&gt;fetchAll(PDO::FETCH_OBJ);</code> in my method for generating list.</p> <h2>index.php</h2> <pre><code> &lt;?php include_once '../../classes/conn/connection.php'; include_once '../../classes/setups/Subdetails_setup.php'; $con = new connection(); $info = new Subdetails_setup($con); $results = $info-&gt;getSubjectInfo(); echo $results; //this is returning a list of objects. My problem is how can i iterate these values ?&gt; </code></pre> <p>and i tried like this <code>echo (each($results));</code> but this is printing my values in a single line like this:- <code>Subject Name 1 FIction1Non FIction2</code></p> <p><strong>&amp; My Subdetails_setup.php Class is having method getSubjectInfo()</strong> :-</p> <pre><code> function getSubjectInfo() { $sub_info = $this-&gt;con-&gt;prepare("SELECT * FROM subjectdetails"); $sub_info-&gt;execute(); $results = $sub_info-&gt;fetchAll(PDO::FETCH_OBJ); foreach ($results as $key) { echo $key-&gt;subject_name; echo $key-&gt;subject_id; } // Return the result array return $results; } </code></pre> <p>Please help me for this. -Ashutosh</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload