Skip to content

Instantly share code, notes, and snippets.

Created Sep 9, 2015
What would you like to do?
Display data horizontally from MySQL table
DROP TABLE IF EXISTS `member_table`;
CREATE TABLE `member_table` (
`id` tinyint(4) NOT NULL AUTO_INCREMENT,
`member_name` varchar(20) NOT NULL,
-- ----------------------------
-- Records of member_table
-- ----------------------------
INSERT INTO `member_table` VALUES ('1', 'Sir Isaac Newton');
INSERT INTO `member_table` VALUES ('2', 'Leonardo Vinchi');
INSERT INTO `member_table` VALUES ('3', 'William Shakespeare');
INSERT INTO `member_table` VALUES ('4', 'Adolf Hitler');
INSERT INTO `member_table` VALUES ('5', 'Siddhartha Gautama');
INSERT INTO `member_table` VALUES ('6', 'Moses');
INSERT INTO `member_table` VALUES ('7', 'Abraham');
INSERT INTO `member_table` VALUES ('8', 'Jesus of Nazareth');
INSERT INTO `member_table` VALUES ('9', 'Walt Disney');
mysql_connect ('localhost','root','password');
mysql_select_db ('test');
$sql_result = mysql_query ("SELECT member_name FROM member_table") or die ('Unable to select'. mysql_error());
$record_count = 0; //Keeps count of the records echoed.
while ($row=mysql_fetch_row($sql_result))
//Check to see if it is time to start a new row
//Note: the first time through when
//$record_count==0, don't start a new row
if ($record_count % 3==0 && $record_count != 0)
echo '</tr><tr>';
echo '<td>';
//Echo out the entire record in one table cell:
for ($i=0; $i< count($row); $i++)
echo $row[$i];
echo '</td>';
//Indicate another record has been echoed:

This comment has been minimized.

Copy link

@tanmoyc96 tanmoyc96 commented Jan 19, 2021

Thank You so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment