sigmahokies Posted November 24, 2015 Share Posted November 24, 2015 Hi everyone, I am still learning. I am trying to create the display the record in vertical columns, but set up the vertical columns with order by last name in MySQL is success, but problem that all table cell are empty that I write to display the record, seem MySQL's query did not answer or delivery the record from database. What did I do wrong? Here my code: $display = "SELECT ID, FirstName, LastName, MonthEx FROM Members ORDER BY LastName";$result = mysqli_query($Garydb, $display); $data = mysqli_num_rows($result);$row = 1;$col = 2; echo "<table border='1'>";for ($i = 0; $i < $data / $col; $i++) {echo "<tr>";for ($j = 0; $j < $col && $row <= $data; $j++, $row++) {echo "<td>".$data['FirstName']." ".$data['LastName']."</td><td><a href='update.php?update=$data[iD]'>EDIT</a></td><td><a href='delete.php?delete=$data[iD]'>DELETE</a></td>\n";}echo "</tr>";}echo "</table>"; funcation is working, but display the record hasn't come out from MySQL... Thank you in advance time. Gary Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 24, 2015 Share Posted November 24, 2015 (edited) $data is only a count. Your actual data is in $result. These are wrong: $data['FirstName'] Edited November 24, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
sigmahokies Posted November 24, 2015 Author Share Posted November 24, 2015 (edited) So, Do i have to change $result from $data, like $result['FirstName']? I did that...it is not showing, still empty in cell in table. Do I have to create 'while' to code with mysqli_fetch_assoc or mysqli_fetch_array instead of 'for'? Please advise me Thanks Edited November 24, 2015 by sigmahokies Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 24, 2015 Share Posted November 24, 2015 With all due respect, your grammar and punctuation is atrocious. I am not a grammar nazi, but what you wrote is very difficult to understand. If you want to get free help, the least you can do is write a clear request. I can't tell if you want the data to go top-down/left-right or left-right/top-down. Do you want this 1 2 3 4 5 6 Or this 1 4 2 5 3 6 Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 24, 2015 Share Posted November 24, 2015 (edited) I am not a grammar nazi, but what you wrote is very difficult to understand. I concur. Very bad grammar. Very hard to understand what you were saying. Edited November 24, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
sigmahokies Posted November 24, 2015 Author Share Posted November 24, 2015 (edited) All right, I admit...English is my ESL - English Second Language. I'm Deaf. I am using American Sign language (ASL), I have problem with English that which conflict with ASL sometimes. I am trying to create a vertical data cell in the table that display the record from database. Please forgive me, I am very fluent in ASL, then English is my second language...once any second langauge, surely little lower skill in language. I might be not good at english, but I can do PHP. I hope everyone will understand. What i want is... 1 4 7 2 5 8 3 6 9 Got it? Thank you for be patient with me. Gary Edited November 24, 2015 by sigmahokies Quote Link to comment Share on other sites More sharing options...
Solution Psycho Posted November 24, 2015 Solution Share Posted November 24, 2015 Try this: <?php //Define the number of columns allowed $max_columns = 3; //Query the data $query = "SELECT ID, FirstName, LastName, MonthEx FROM Members ORDER BY LastName"; $result = mysqli_query($Garydb, $query); //Put results into an array $rows = array(); while($rows[] = mysqli_fetch_array($result, MYSQLI_ASSOC)) {} //Determine the number of rows $max_rows = ceil(count($rows) / $max_columns); //Separate data array into chunks for each column $data_chunks = array_chunk($rows, $max_rows); //Generate HTML output (into a variable) $output = ''; //Iterate over the array chunks while not empty while(count($data_chunks[0])) { //Open new row $output .= "<tr>\n"; //Get next record from each chunk foreach($data_chunks as &$chunk) { //Remove the first element off of the current chunk $data = array_shift($chunk); if(empty($data)) { continue; } //Create the $output .= "<td>{$data['FirstName']} {$data['LastName']}</td>"; $output .= "<td><a href='update.php?update={$data['ID']}'>EDIT</a></td>"; $output .= "<td><a href='delete.php?delete={$data['ID']}'>DELETE</a></td>\n";; } //Close the row $output .= "</tr>\n"; } ?> <html> <head></head> <body> <table border='1'> <?php echo $output; ?> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
sigmahokies Posted November 25, 2015 Author Share Posted November 25, 2015 Psycho, It is working now, but I need to learn to do the logic in script in PHP. There are some things in PHP I don't understand fully. Like, I wonder why some people use "%", I know it is about like round, but how it does work? Also, I notice you put - ".=" it is a dot with equal, how it does work? I mean, why do you put ".=" instead of "==" or ">="...? I have few books about PHP, they don't explain very clearly about those. Can you give me a link for advance tutorial in PHP to use those letters? Thanks, Gary Quote Link to comment Share on other sites More sharing options...
Barand Posted November 25, 2015 Share Posted November 25, 2015 Have you ever considered looking at the PHP reference manual? Like, I wonder why some people use "%", I know it is about like round, but how it does work? http://uk1.php.net/manual/en/language.operators.arithmetic.php Also, I notice you put - ".=" it is a dot with equal, how it does work? I mean, why do you put ".=" instead of "==" or ">="...? http://uk1.php.net/manual/en/language.operators.assignment.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.