How to Store Database records in an Multidimentional Array in PHP


About Array in PHP

Like any other programming languages or  web languages, array plays an important role in storing many data.
Storing single array elements in PHP in as any normal languages.
Syntax : array () ;
But to store many array within an array, there are Multidimensional Arrays. PHP have the Array of Array concept. 
Syntax: array (array());

Array in Arrays in PHP to store database values.

Well this post seems to be simple. Yes , i had an issue with storing the values in multidimensional arrays, but there haven't been any proper post till yet, of actual way of storing and dynamic looping used for storing data.

So lets start,
I want to store watches database values. For each watch there are 5 parameters (coloumns).

First I will extract the data from database using select query
$res = mysql_query("select * from watches ") or die(mysql_error());

Next, we should initialize array of array for storing data
$wat = array(array());

Now, below is the simple snippet to dynamically store values in that $wat array.

$i=0;
while($row = mysql_fetch_array($res))
{
$j=0;
  $wat[$i][$j++] = $row['brand'];
  $wat[$i][$j++] = $row['modelname'];
  $wat[$i][$j++] = $row['price'];
  $wat[$i][$j++] = $row['gender'];
  $wat[$i][$j++] = $row['movement'];
  $i++;
}

Now if we want to display all the contents of data in that array, we can do something like this.

for($i=0 ; $i<$rows ; $i++)
      for($j=0 ; $j< $columns; $j++)
      {
        echo $wat[$i][$j]."<br>";
      }
}

So we had store and displayed the data from the database successfully.
If you liked the post, do share and like us at AnonHackSociety

28 comments

Thanks a lot for all your valuable article! We are really happy about the your thoughts... SAP Training in chennai

Reply

Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care.As always, we appreciate your confidence and trust in us...!!! SAP Training in Chennai


Reply

Really very nice blog information for this one and more technical skills are improve,i like that kind of post.



SAP training in Chennai

Reply

Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us.

SAP training in Chennai

Reply

I have been following you for a couple of months now but this is my first time commenting on a blog post. Thank you for sharing your knowledge and experience with us. Keep up the good work. Already bookmarked for future reference.

SAP training in Chennai

Reply


These provided information was really so nice,thanks for giving that post and the more skills to develop after refer that post. Your articles really impressed for me,because of all information so nice.

SAP training in Chennai

Reply

Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us.

SAP training in Chennai

Reply

I have been following you for a couple of months now but this is my first time commenting on a blog post. Thank you for sharing your knowledge and experience with us. Keep up the good work. Already bookmarked for future reference.

SAP training in Chennai

Reply


That is very interesting; you are a very skilled blogger. I have shared your website in my social networks!


SAP training in Chennai

Reply




Great and useful article. Creating content regularly is very tough. Your points are motivated me to move on.


SEO Company in Chennai

Reply

All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.


Digital Marketing Training in Chennai

Reply

All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.


Digital Marketing Company in Chennai

Reply



This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.

Digital Marketing Company in Chennai

Digital Marketing Services in Chennai

Reply

This idea is mind blowing. I think everyone should know such information like you have described on this post. Thank you for sharing this explanation.Your final conclusion was good. We are sowing seeds and need to be patiently wait till it blossoms.

CRO Agency in Chennai

Reply

new year wishes for whatsapp christmas whatsapp pictures christmas nails designs 2016 Many people’s hope to others by writing the letters. They write letters and sent it to their friends, relatives, and the others. This is a beautiful style to wish someone; you can also do this. Many people wish the peoples by the mobile message in the event of Christmas. This is the digital style which uses by the youngster on the events.

Reply

christmas themed nails christmas pictures for facebook new year free wishes 2017 Here you may get all gifts and surprises which you may not get from any other website.

Reply

Thank you for sharing such a nice and interesting blog with us. Hope it might be much useful for us. keep on updating...!!
seo company in india
digital marketing company in india
seo company in chennai
digital marketing company in chennai

Reply

KSEEB Board is going to declare Karnataka SSLC Result today. Students can check the results at official website of karresults.nic.in.

Reply

KSEEB Board is going to declare Karnataka SSLC Result today. Students can check the results at official website of karresults.nic.in.

Reply

Post a Comment