<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Moaz</title>
    <description>The latest articles on DEV Community by Moaz (@web-developer-in-lahore).</description>
    <link>https://dev.to/web-developer-in-lahore</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3772964%2F7bcdd9cd-2203-4684-b962-e9f7cd4d86ba.png</url>
      <title>DEV Community: Moaz</title>
      <link>https://dev.to/web-developer-in-lahore</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/web-developer-in-lahore"/>
    <language>en</language>
    <item>
      <title>Why to Fetch Database Records into an Array in Core PHP?</title>
      <dc:creator>Moaz</dc:creator>
      <pubDate>Tue, 24 Feb 2026 04:10:47 +0000</pubDate>
      <link>https://dev.to/web-developer-in-lahore/why-to-fetch-database-records-into-an-array-in-core-php-2edm</link>
      <guid>https://dev.to/web-developer-in-lahore/why-to-fetch-database-records-into-an-array-in-core-php-2edm</guid>
      <description>&lt;p&gt;In my last post &lt;a href="https://dev.to/web-developer-in-lahore/how-to-fetch-database-records-into-a-multidimensional-array-using-core-php-l3n"&gt;here&lt;/a&gt; I explained "How to Fetch Database Records into a Multidimensional Array using Core PHP". But I left the question unanswered and did not provide details about why do we need to store database data in a multidimensional array while we are already storing the data in associative array through fetch_assoc() function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let me explain my point&lt;/strong&gt;&lt;br&gt;
In our last code we are storing and retrieving name and email thorough $row['name'], $row['email'] respectively. Then we are again saving this data in $data[0][$i] and $data[1][$i] respectively in a while loop.&lt;/p&gt;

&lt;p&gt;The question is why we are storing name, email data in $data array. As this is a temporary storage and we do not need it as we can use $row array instead?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is the reason&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Suppose we have employee data in our database as "name", "email", "phone", "salary", "loan-amount", "time_period".&lt;br&gt;
As data shows employees have taken loans for a fixed period of time. Now our task is to calculate compound interest for each employee and we have to use this compound interest at 4 or 5 different places in this page. &lt;/p&gt;

&lt;p&gt;Will it not be convenient that we calculate the interest once and use it again and again? instead of calculating interest again and again using $row array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is the code for more explanation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn-&amp;gt;connect_error) {
  die("Connection failed: " . $conn-&amp;gt;connect_error);
}

$sql = "SELECT * FROM table_name limit 15";
// Execute the SQL query
$result = $conn-&amp;gt;query($sql);

$data = array();

// initialize counter
$i = 0;
// Process the result set
if ($result-&amp;gt;num_rows &amp;gt; 0) {
  // Output data of each row
  while($row = $result-&amp;gt;fetch_assoc()) {
 // Storing database data into array
    $data[0][$i] = $row['name'];
    $data[1][$i] = $row['email'];
    $data[2][$i] = (int)$row['salary']*6;
    // we are calculating interest once in a year while interst rate is 5%
    $data[3][$i] = $row['salary']*(1+1/5)^($row['time'] * 5);
    // increase counter by 1
    $i = $i+1;
  }
} else {
  echo "0 results";
}

$conn-&amp;gt;close();
?&amp;gt;

&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Custom PHP Script&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
&amp;lt;?php

// display data
echo "&amp;lt;table border=1 cellspacing=0 cellpadding=3&amp;gt;";
for($v=0; $v&amp;lt;count($data[0]); $v++) {
echo "&amp;lt;tr&amp;gt;";
echo "&amp;lt;td&amp;gt;";
echo "Name ";
echo $v+1;
echo " : ";
echo "&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;";
echo $data[0][$v];
echo "&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;";
echo " ---- --- -- ";
echo "&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;";
echo "Email ";
echo $v+1;
echo " : ";
echo "&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;";
echo $data[1][$v];
echo "&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;";
echo " ---- --- -- ";
echo "&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;";
echo "6 Months Salary ";
echo $v+1;
echo " : ";
echo "&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;";
echo $data[2][$v];
echo "&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;";
echo " ---- --- -- ";
echo "&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;";
echo "Compound Interest ";
echo $v+1;
echo " : ";
echo "&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;";
echo $data[3][$v];
echo "&amp;lt;/td&amp;gt;";

echo "&amp;lt;/tr&amp;gt;";
}
echo "&amp;lt;/table&amp;gt;";
?&amp;gt;

&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you can see we calculated compound interest once and stored it in $data[2][$v]. Now we can use $data[2][0], $data[2][1], $data[2][2] instead of writing that complex compound interest code every time. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is output of the above code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fra1dmzgoyjemhkfekjve.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fra1dmzgoyjemhkfekjve.png" alt=" " width="800" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I use similar logic while building custom CRMs for my clients at KM Sol. Check out my portfolio: &lt;a href="https://webpk.online/a" rel="noopener noreferrer"&gt;https://webpk.online/a&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>webdev</category>
      <category>pakistan</category>
      <category>coding</category>
    </item>
    <item>
      <title>How to Fetch Database Records into a Multidimensional Array using Core PHP</title>
      <dc:creator>Moaz</dc:creator>
      <pubDate>Mon, 23 Feb 2026 20:32:36 +0000</pubDate>
      <link>https://dev.to/web-developer-in-lahore/how-to-fetch-database-records-into-a-multidimensional-array-using-core-php-l3n</link>
      <guid>https://dev.to/web-developer-in-lahore/how-to-fetch-database-records-into-a-multidimensional-array-using-core-php-l3n</guid>
      <description>&lt;p&gt;Hi everyone! Today I want to share a simple way to fetch data from a MySQL database and store it in a multidimensional array using Core PHP. This is a very light-weight approach, perfect for small custom projects or CRMs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn-&amp;gt;connect_error) {
  die("Connection failed: " . $conn-&amp;gt;connect_error);
}

$sql = "SELECT * FROM table_name limit 15";
// Execute the SQL query
$result = $conn-&amp;gt;query($sql);

$data = array();

// initialize counter
$i = 0;
// Process the result set
if ($result-&amp;gt;num_rows &amp;gt; 0) {
  // Output data of each row
  while($row = $result-&amp;gt;fetch_assoc()) {
 // Storing database data into array
    $data[0][$i] = $row['name'];
    $data[1][$i] = $row['email'];
    // increase counter by 1
    $i = $i+1;
  }
} else {
  echo "0 results";
}

$conn-&amp;gt;close();
?&amp;gt;

&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Custom PHP Script&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
&amp;lt;?php

// display data
for($v=0; $v&amp;lt;count($data[0]); $v++) {
echo "Name ";
echo $v+1;
echo " : ";
echo $data[0][$v];
echo " ---- --- -- ";
echo "Email ";
echo $v+1;
echo " : ";
echo $data[1][$v];

echo "&amp;lt;br&amp;gt;";
}

?&amp;gt;

&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this logic, I am using two main indices in the $data array:&lt;/p&gt;

&lt;p&gt;Index 0 stores all the Names.&lt;/p&gt;

&lt;p&gt;Index 1 stores all the corresponding Emails.&lt;br&gt;
This makes it easy to loop through the names and emails separately if needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do we need to store database data in an array?&lt;/strong&gt;&lt;br&gt;
Accessing data from a local array is much faster than performing repeated queries to the database server for every piece of information. You can load necessary data once into an array and work with it locally within the script's execution.&lt;/p&gt;

&lt;p&gt;Please note that fetch_assoc() also returns database rows as PHP associative arrays. &lt;/p&gt;

&lt;p&gt;I use similar logic while building custom CRMs for my clients at KM Sol. Check out my portfolio: &lt;a href="https://webpk.online/a" rel="noopener noreferrer"&gt;https://webpk.online/a&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>corephp</category>
      <category>website</category>
      <category>web</category>
    </item>
    <item>
      <title>How I built a Custom Real Estate CRM Using PHP and MAriaDB</title>
      <dc:creator>Moaz</dc:creator>
      <pubDate>Sat, 14 Feb 2026 17:51:14 +0000</pubDate>
      <link>https://dev.to/web-developer-in-lahore/how-i-built-a-custom-real-estate-crm-using-php-and-mariadb-iok</link>
      <guid>https://dev.to/web-developer-in-lahore/how-i-built-a-custom-real-estate-crm-using-php-and-mariadb-iok</guid>
      <description>&lt;p&gt;How I built a Custom Real Estate CRM Using PHP and MAriaDB&lt;/p&gt;

&lt;p&gt;I started from scratch. I written codes in core php. This is a property CRM (Customers Relationship Management) web application for real estate users. Real estate dealers/users can easily manage their customers, properties, dealers lists, booking and agents working in their agency.&lt;/p&gt;

&lt;p&gt;This application also allows users to see reminders set by call date of properties and customers on dashboard. There are lots of hidden features in it like admin can assign job/deal to any of the agent. The admin can also take job from one agent and assign it to another agent. Please don't be confused the agent with dealer. Agent is working in agency while dealer is the property dealer working in market.&lt;/p&gt;

&lt;p&gt;Another hidden feature in this CRM is that when admin assigns a job to the agent, the agent receives an email. &lt;/p&gt;

&lt;p&gt;I am currently taking this CRM to an advanced level. I'd love to hear your thoughts or suggestions!&lt;/p&gt;

&lt;p&gt;Here is a demo of my work.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://pro-demo.42web.io/login.php" rel="noopener noreferrer"&gt;https://pro-demo.42web.io/login.php&lt;/a&gt;&lt;br&gt;
Username: admin&lt;br&gt;
Password: admin123&lt;/p&gt;

</description>
      <category>php</category>
      <category>mysql</category>
      <category>crm</category>
      <category>realestate</category>
    </item>
  </channel>
</rss>
