Skip to content
Advertisement

(PHP,MySQL) Adding information from an SQL table to a PHP web page table which has same field id

My English is not so well and I am new with php. So, maybe you can be bored with my question. I am really sorry for that.

Here’s the Question: I have a table created in SQL database like this:

-   ID       Name        PICTURE
 -   1       John        john.jpg
 -   1       dora        h.jpg
 -   1       Dane        hkjpg
 -   2       Mougli      f.jpg
 -   3       Mona        g.jpg

and I want to show the data in a table created in my web page like this:

-   ID       Name        PICTURE
 -   1       John        john.jpg
 -   1       dora        h.jpg
 -   1       Dane        hkjpg

I Want to show all the information in my web page which has the id “1” and others will not be in the table. I want to use a loop to do that. If you know how to do that then please try to answer with the full php code( I mean the code should start from connecting database to the page and end to looping the information in the table. Of-course it depends on you if you want to write the full code. But it would be very helpful for me).

Thanks in advance.

Advertisement

Answer

I would recommend using PDO: https://www.php.net/manual/en/class.pdo.php You want to start with the __construct and query functions. Query will return a PDOStatement object that you can fetch. Your code should look like this:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement