Тёмный

47: Inserting database results into array in PHP - PHP tutorial 

Dani Krossing
Подписаться 477 тыс.
Просмотров 144 тыс.
50% 1

Inserting database results into array in PHP - Learn PHP backend programming. Today we will learn how to insert data from a database table into an array.
➤ GET ACCESS TO MY LESSON MATERIAL HERE!
First of all, thank you for all the support you have given me!
I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!
I am now using Patreon to share improved and updated lesson material, and for a small fee you can access all the material. I have worked hard, and done my best to help you understand what I teach.
I hope you will find it helpful :)
Material for this lesson: / lesson-material-42361704

Опубликовано:

 

13 ноя 2016

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 98   
@Kodeispoetry
@Kodeispoetry 4 года назад
The content delivery style is excellent. No Fluff. I loved that.
@abzalbotbayev
@abzalbotbayev 5 лет назад
OMG, thx bro. I'm about 10 days can't understand how this work. This video is helpfull!
@appleproahed
@appleproahed 6 лет назад
Hello Daniel, Just a heads up when you show us a dump from a print_r then instead of just doing that, so it looks so messy, then arooung the print_r(); you can echo '' and close it after the print_r functions like echo '' and you will get a much more clean look..
@roykossley4561
@roykossley4561 Год назад
Man you 're a life saver..Still helpful in 2023 👌
@abnermolina8962
@abnermolina8962 6 лет назад
Great!!! thanks i understand it.
@atendimentorocodd6631
@atendimentorocodd6631 4 года назад
You just saved me. Thanks a lot!
@invsg5072
@invsg5072 2 года назад
very well explained! Thank you so much!
@toast_hawaii
@toast_hawaii 5 лет назад
Thank you dude, im currently at my exams and you really helped me out. You dont know how much you helped people around the word with this video
@fadhilaasyam5895
@fadhilaasyam5895 4 года назад
Hi daniel, thans god you very help me out on my final project. This was very perfect solver for machine learning development. Love you, i'll promote ur channel as i cant give nothing. I am from indonesia btw. Thx
@nikolaoschairopoulos9005
@nikolaoschairopoulos9005 4 года назад
thank you so much!! you help me for my database project for the university (hello from Athens)
@LearnProgrammingYourself
@LearnProgrammingYourself 5 лет назад
very nice approach of explanation.Thank you, sir.
@jiph294
@jiph294 5 лет назад
Wow. You helped me out so much
@programmerinnovation1782
@programmerinnovation1782 5 лет назад
this video is helpfull !!!!
@alrenjaygabasan8838
@alrenjaygabasan8838 2 года назад
This gives me a head start, because i code in another class which doesn't give the require output on my code thanks a bunch.
@JOHNSWORLD-kw8zr
@JOHNSWORLD-kw8zr 3 месяца назад
Thank you Sir . 'helped a lot.
@nogafouz2174
@nogafouz2174 2 года назад
really you have awesome way in explain
@nakiapringley5391
@nakiapringley5391 2 года назад
Great video 💯💯💯💯
@dantewins
@dantewins 4 года назад
love your videos
@lasithadulshan7357
@lasithadulshan7357 2 года назад
Thank You!
@gazwanhayat2637
@gazwanhayat2637 2 года назад
Thank you very much.
@taynarabarboza5842
@taynarabarboza5842 3 года назад
thank you!
@dirkhuizinga2169
@dirkhuizinga2169 5 лет назад
Hey, I learn a lot from this channel. I'm just a beginner in php and mysqli. Yet I already have a compexe question. I am looking for a code / instruction how to make a matrix (multiple dimensional array ????? (I don't know)). What I have is a three table database table 'user' a table 'role' and a connection table 'person2role'. Now I am looking at how I can display the roles horizontally and the users vertically. where the tables intersect should be a +. for example: role1 role2 role3 user1 x user2 x x user3 x
@Holycrabbe
@Holycrabbe 6 лет назад
if I could slam a super like button i had done so! thank you my fine sir :D !
@Dani_Krossing
@Dani_Krossing 6 лет назад
[!!SLAM!!] !!! .. .. .. .. ) ) ) ) ) ) ) ) O: ! (me taking the full force of the shock wave)
@khudaijasiddiqui4749
@khudaijasiddiqui4749 4 года назад
mmtuts i is shaken .O.
@antoniofuller2331
@antoniofuller2331 3 года назад
Hulk smash the subscribe button
@paulklimenko8419
@paulklimenko8419 5 лет назад
Hello nice tuts. I HAVE A QUESTION. Related to array, can you explain why we put html input checkbox name= "checkbox [ ] " . How those brackets as key can turn into value in an array? I dont get it. Thanks pal you awesome.
@TheClarkKnight9
@TheClarkKnight9 6 лет назад
Does anyone know what the best way to pass a multi-dimensional array to a new page is. Is it best to use SESSIONS or to serialise the variable and use POST and then unserialise on the other page? Or is there some other method that would be more appropriate?
@shyakaleonce1804
@shyakaleonce1804 5 лет назад
Greetings Sir! From your example how could i use to save only these ids,texts in another table? Im using php PDOs? Waiting to hear from you!
@pyrocom8338
@pyrocom8338 4 года назад
v goooood
@user-testo21347
@user-testo21347 3 года назад
Nice
@ScreenPrintR
@ScreenPrintR 7 лет назад
As I've been flollowing your tutorials, other subjects on RU-vid pop up. Several have been Learn to send SMS Text in PHP. Why would someone want to send or receive text, and how would we implement such an application?
@sahinyasar9119
@sahinyasar9119 5 лет назад
can we use object of javascript as like array with foreach in php?
@yongxinzhang754
@yongxinzhang754 5 лет назад
Hi, is it possible that if I only want selected columns in array (not all at once)? Fx. I have 7 columns in my table in database. I only want to insert results from column nr. 6, 1 and 2, and I want to insert these results in this order (row[6], row[1], row[2]). What should I do so??
@abbashomayooni4749
@abbashomayooni4749 4 года назад
Hi Daniel, thank you for this tutorial, it's very helpful. but where are the 36-44 episodes ??!! there're missing. please advise. thank you
@noahbroyles8828
@noahbroyles8828 3 года назад
1:24: "Which I know is not correct" Big LOL!!! 🤣
@Strelarck
@Strelarck 3 года назад
"big lol"
@pushparajvaghela3476
@pushparajvaghela3476 5 лет назад
Would it not be better if you use references like : 1D Arrays -> | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 2D Arrays -> | 00 | 01 | 02 | 03 | | 10 | 11 | 12 | 13 | | 20 | 21 | 22 | 23 | | 30 | 31 | 32 | 33 | 3D Arrays -> as cubes instead of just saying multi-dimensional array Also you should explain how the mysqli_query() function returns the result like id text ------------------------- 0 | 1 | Hi | -> Array 1 1 | 2 | there | -> Array 2 2 | 3 | friend | -> Array 3 ResultArray = ( Array1, Array2, Array3 ) ;
@eminaliyev4953
@eminaliyev4953 4 года назад
For printing all the rows you can try that: for($i = 0; $i < (mysqli_num_rows($result)); $i++){ foreach($data[$i] as $item){ echo $item." "; } echo ""; }
@cacurazi
@cacurazi 6 лет назад
For a better overview of your array do this:
@jaydevvara9457
@jaydevvara9457 6 лет назад
How to retrieve data from database and show in different different checkbox?
@salahuddinakon2835
@salahuddinakon2835 5 лет назад
what about if I have some empty row inside column result? how can I escape that empty row? please help....
@Kristin-yf9rq
@Kristin-yf9rq 4 года назад
Could this be applied to a java program instead of a website and still work correctly?
@jacksmith3386
@jacksmith3386 7 лет назад
Can you please make coffeescript tutorials?
@mnunez6153
@mnunez6153 3 года назад
hi, i'm stuck on how i can do the reverse, that is, how to insert every data (from the result of COUNTING how many times a word appear in the column) into a table. I was able to display the result, but i need to also insert the data to a table in db. Pls. advice. thanks
@laughout199
@laughout199 4 года назад
Hi am having issue fetching several data from mysql table with repetition, can I get help
@DramaticOgre
@DramaticOgre 6 лет назад
Is it possible to get each value inside the text column separately(not all at once)? And also, without referencing the id for each text. Can someone answer this please?
@djleisheng
@djleisheng 6 лет назад
First, change your $sql variable: // Get only the text column $sql = "SELECT text FROM data"; then leave everything else the same, but change your foreach loop: foreach($data as $d) { foreach($d as $key=>$value) echo "$value "; } Let me know if that's what you were looking for!
@DramaticOgre
@DramaticOgre 6 лет назад
Lei Sheng Thanks for your reply. I tried your code and it's echoing out every value from the "text" column. What I'm looking to do is, for example from the text column, run one query and echo out only "Hi", then run another query to echo out only "You". I would like to do this without referencing the id column. If i was using the id as a reference I could change the sql variable to $sql="SELECT text FROM data WHERE id=4" But I would like to do the same task without referencing a primary key. Is there a way to put the column values in a index? [0],[1],[2]... etc
@kevinfoendoe6987
@kevinfoendoe6987 3 года назад
@@djleisheng Hii, Do you know how i can access the fetched data in console log for example? I followed the tutorial, and I'm able to echo my results on the screen. But is there a way i can console log the result by typing something in js?
@jayveepontanares5837
@jayveepontanares5837 5 лет назад
how to put these into count array?
@inadogood5819
@inadogood5819 3 года назад
Hi can you please make a video on how to insert array result into database in PHP?
@peterlustig502
@peterlustig502 5 лет назад
why do you name the part which is connecting to the database and executing a piece of sql code $result ? wouldnt $execute or $sqlCode be better?
@shrutiupari
@shrutiupari 6 лет назад
how to use insert query and display the inserted data in json format?
@Dani_Krossing
@Dani_Krossing 6 лет назад
I haven't started a JSON course yet, but it is on my "to-do" list :)
@jeffersondulay3756
@jeffersondulay3756 4 года назад
Hello mmtuts how do i compare database data with form input data? They are both sentences, how do i compare each of the words of those data one by one?
@Nicole-ch1qe
@Nicole-ch1qe 5 лет назад
This tutorial playlist has been amazing so far! I'm super new to php coding and I make sure to follow your tutorials asclosely as possible and it has gone well :) I did the same with the code in this video and created the database and table like yours and keep getting this error message: Warning: mysqli_connect(): (HY000/1045): Access denied for user ''@'localhost' (using password: NO) in C:\xampp\htdocs\trialsandtribs\ARRAYS\dbh.php on line 8 connection failed: Access denied for user ''@'localhost' (using password: NO) I don't know how to fix this or where to start. Please help *weeps like child*
@edwinbasa2804
@edwinbasa2804 5 лет назад
Nicole did u put a password in ur code on localhost
@mydimeisup5103
@mydimeisup5103 7 лет назад
Cool video but quick question. How would this be helpful in the sense that I can just use fetch assoc $row[]
@Dani_Krossing
@Dani_Krossing 7 лет назад
Like the video says towards the end, when we get into OOP PHP later on, we will need to pass on our database data between multiple documents and OOP classes. One way of doing this is by inserting our results into an array. I could also imagine there being other uses for this besides OOP, which makes it useful for people who might be searching for a way to do this. :)
@mydimeisup5103
@mydimeisup5103 7 лет назад
Ahh ok, thanks for the info.
@koby6192
@koby6192 7 лет назад
Could you help me with my footer? :s
@dc4rts766
@dc4rts766 4 года назад
after inserting array to database how about updating it using php
@user-tq1nw2lr2f
@user-tq1nw2lr2f 7 лет назад
8002f1f9 my ps3 error how to fix it
@rahullingan2119
@rahullingan2119 4 года назад
Hii... For this below lines... foreach ($datas as $loopvar ){ echo $loopvar['text']; } I'm getting this Notice: undefined index:text in c:\..... Can u help me on this.?!
@NicolasSouzaNCS_ofc
@NicolasSouzaNCS_ofc 4 года назад
I try this but returns from the second line ... who i can fix that?
@mmpadyak7491
@mmpadyak7491 5 лет назад
Hi sir ,
@hkn5539
@hkn5539 2 года назад
Can someone help: in fact there is no difference between the array result and the array datas. Is that right?
@legendofgaming8481
@legendofgaming8481 2 года назад
I am getting this error: Cannot use a scalar value as an array
@QuranicWorldSinghateh
@QuranicWorldSinghateh 5 лет назад
hello sir how are you doing, thank you for you tutorial, but i have one issue that i want you to help me because am working on my theist and i have error to submit my student attendance using mysqli array here are the code below ( =========== this part is the form side ======== × Mark Class Attendance Grade *
@JY-xv7ic
@JY-xv7ic 7 лет назад
how to insert data array to database?
@Dani_Krossing
@Dani_Krossing 7 лет назад
If you have a fixed amount of data in your array, you first seperate the array using the PHP explode() function. Then you assign a variable to each data which allow you to insert it into the database using a INSERT statement.
@pianoLee-sx9dx
@pianoLee-sx9dx 6 лет назад
how do you use the explode function? Is this essential in order to insert into the database?
@pianoLee-sx9dx
@pianoLee-sx9dx 6 лет назад
but how can you use the explode function to insert into separate rows?
@dishashetty9132
@dishashetty9132 5 лет назад
It would be great if you show how to do this in C language
@antoniofuller2331
@antoniofuller2331 3 года назад
F**k C
@Luism-tz2ey
@Luism-tz2ey 6 лет назад
how to insert into array in pdo?
@Dani_Krossing
@Dani_Krossing 6 лет назад
My PDO series teaches this.
@bradcasper4823
@bradcasper4823 Год назад
Shouldn't you close the connection?
@Dani_Krossing
@Dani_Krossing Год назад
Connections get automatically closed once the script is done running. 🙂 It's seen as a optional extra step, but you can close it if you want more control over when exactly it closes. You can read more about it here: www.php.net/manual/en/mysqli.close.php
@bradcasper4823
@bradcasper4823 Год назад
@@Dani_Krossing Thank you, I didn't know this.
@pro_hacker6969
@pro_hacker6969 4 года назад
actually data is the plural and datum is singular that's according to my own knowledge
@arnelmaghirang8426
@arnelmaghirang8426 3 года назад
Multidimensional array is hard one to understand.
@aspirine999
@aspirine999 6 лет назад
- how much data do we need? - like 8 datas
@Jay-hr9ci
@Jay-hr9ci 5 лет назад
I'm looking for a way to do the opposite lol
@tunabehe2694
@tunabehe2694 2 года назад
Where is the next part bro ???
@Dani_Krossing
@Dani_Krossing 2 года назад
In the playlist bro
@tunabehe2694
@tunabehe2694 2 года назад
@@Dani_Krossing there are only 15 videos in the php playlist
@Dani_Krossing
@Dani_Krossing 2 года назад
No there is 65. Make sure you choose the right PHP playlist on my channel. 🙂 I have 3 different PHP playlists.
@AlienEyes
@AlienEyes 3 года назад
I swear, you are getting paid every time you say array or something
@antoniofuller2331
@antoniofuller2331 3 года назад
I need a raise. Arrays
@Pythogoras570BC
@Pythogoras570BC Год назад
Thanks for the presentation. It helped me solving several questions. However, I am using PHP 8.2.2 and the code of the presentation generates an error. I am presenting the problem that might give you an idea for resolving it The code below reads the data $i = 0; $j = 0; while ($row = mysqli_fetch_array($result)) { $dbArr[] = $row; $dbArrTest[$i][$j++] = $row['strName']; $dbArrTest[$i++][$j] = $row['meaning']; } The code below just tests the reading $i = 0; foreach ($dbArr as $strF) { if ($i !== 0) { echo $i . ": " .$strF['strName'] . " : " . $strF['meaning']; echo ""; } $i++; } If $i = 0 --> PHP 8.2.2 generates an error. I have no idea why! I bypassed it by just skipping value $i=0 The same is happening no matter what is the initial value of $i (like 1, 2, 3). My test shows that the problem is generated when rtrying to echo the 1st value of $strF, that is EMPTY!!!
Далее
48: Different types of array in PHP - PHP tutorial
2:34
Wait for the BOWLING BALL! 👀
00:38
Просмотров 8 млн
Learn JSON in 10 Minutes
12:00
Просмотров 3,1 млн
Learning MySQL - JSON in MySQL
19:12
Просмотров 64 тыс.
PHP Tutorial (& MySQL) #7 - Arrays
16:57
Просмотров 108 тыс.
Wait for the BOWLING BALL! 👀
00:38
Просмотров 8 млн