Let say you have a table called students with two fields fname and age.
insert into students (fname, age) values
('Kusal', '26'),
('Tom', '18'),
('Ann', '23')
Remember to give the column names in the query.
insert into students (fname, age) values
('Kusal', '26'),
('Tom', '18'),
('Ann', '23')
$result = mysql_query("select count(id) from table");
$data = mysql_fetch_array($result);
$all_rows = $data[0];
$result = mysql_query("select id from table");
$all_rows = mysql_num_rows($result);
<?php
//set your DB connection
mysql_connect('localhost', 'root', '');
//select your DB
mysql_select_db('test');
$query = "SHOW TABLES";
$result = mysql_query($query);
while($data = mysql_fetch_array($result))
{
echo $data[0];
echo '<br />';
}
?>
<?php
//include your DB connection
$query = "describe your_table_name";
$result = mysql_query($query);
//loop through each table column attribute
while($data = mysql_fetch_array($result))
{
echo $data['Field'].', '; //field name
echo $data['Type'].', ';//feild type
echo $data['Null'].', ';// null or not
echo $data['Key'].', ';//primary key or not
echo $data['Default'].', ';//default value
echo $data['Extra'];// like auto increment
echo '<br />';
}
?>
<?php
$time_now = time();
echo $time_now; //output example: 1219848654
echo '<br />';
$str_time = date('Y-m-d H:i:s', $time_now);
//look at php date function for more options
echo $str_time; // 2008-08-27 14:50:54
?>
$result = mysql_query('SELECT * FROM tbl_name');
echo mysql_result($result, 5); // output 6th row
<?php mysql_connect("localhost","root",""); mysql_select_db(test); $q = "select MAX(id) from tbl_name"; $result = mysql_query($q); $data = mysql_fetch_array($result); echo $data[0]; ?>
INSERT INTO your_tbl VALUES ('14:26:05')
<?php
$today = date("Y-m-d"); //todays date
$query = "select * from tbl where DATE(c_timstp) = $today";
$result = mysql_query($query);
?>
select count(*) as num, ID, Name from table
group by ID,Name
having count(*) > 1
+-----+------+------------+
| num |ID | Name |
+-----+------+------------+
| 3 | 1 | Kuppiya |
+-----+------+------------+
| 2 | 3 | Apple |
+-----+------+------------+
SELECT * FROM table_name ORDER BY RAND() LIMIT 0,1