mysql displaying all contains of the table - php

Is it possible to display the mysql table using php, i mean display the records with field names without specifying the row names.
example
|id|name |address |status | <--- this is the field in the mysql table
|1|name1 |address1 |status1| <-- this is the records
and more records...

Just an idea:
Run DESCRIBE tablename and get field names/type
Run SELECT * FROM tablename and get records

If I understand you correctly you want to display all records in the table?
$sql = mysql_query("SELECT * FROM tabel")
the star means you will select all rows. change table to your table name..
Now all your table information is stored in $sql

Related

How to get get all the data from table and if same value repeated in one column that row should count once?

leave_request tablein my table emp_id column contains duplicate data 3 times. i want to select all the data from the table and the duplicate data to count as once. here i am providing the screenshot of my table structure
You can try below -
select max(id),emp_id, emp_name
from tablename
group by emp_id, emp_name

MySQL Query to move/copy certain rows rather than the entire table?

I'm currently using the following to move/copy the entire table from one table to another, which works perfectly.
INSERT INTO archivedpks SELECT * FROM pks
However I want to be able to specify what rows I want to move from the pks table to the archivedpks table.
My table has an id column, I want to only move the rows with an id from 25 to 250
How would I modify the query to only work on those rows?
INSERT INTO archivedpks SELECT * FROM pks WHERE id>=25 and id<=250

i want to fetch all record from my database table without recent added record

i want to fetch all record from MySQL database table using PHP without last added record
I have 4 Columns in the Table, ID(auto) & title and message.
You can use this, if as you say, ID is auto_increment
$sql = "SELECT * FROM table WHERE ID != (SELECT MAX(ID) FROM TABLE) ORDER BY ID";
This is selecting all the records from your table, ordered by id, where the id is not the biggest one.

How do I find which of two tables has the row with a given value in a known column

If I have two tables in a MySQL database that both have a column called order_number, given an order_number value but not knowing which table it comes from how would I go about setting up a query that would return the name of the table it was found in?
I am particularly interested in the name of the table so I can set up subsequent updates to that table.
Also, I am using PHP for the handling of the query.
select "tableA" as tableName,order_number from tableA where order_number=5
UNION
select "tableB" as tableName,order_number from tableB where order_number=5;

MySQL create table containing values from a column in another table

Lets say I have a table tilistings with a dozen columns, and about 2,000 rows there is one column cityname that has probably 50 different values in it. What I want to do, is search through the tilistings and create another table that just contains the 50 different values from cityname without duplicating any names....basically if cityname had the values a,b,a,c,b,b,d,a,a,d,d,c I would only want the new table to contain a,b,c. Is there a pre-built MySQL function to do so? Otherwise, just point me in the right direction to do this with PHP. I can create the table, just looking to populate it.
Or do it all in SQL, if you already have created a table named cities with a single column cityname:
INSERT INTO `cities` (`cityname`)
SELECT DISTINCT `cityname` FROM `tilistings`;
Or crate the table from the SELECT:
CREATE TABLE `cities`
SELECT DISTINCT `cityname` FROM `tilistings`;
You can get the unique city names by performing the following query:
SELECT DISTINCT cityname FROM tilistings
Then loop through those and INSERT them into your new table with PHP or INSERT INTO ... SELECT.

Categories