Jump to content

mattix

Members
  • Content Count

    30
  • Joined

Community Reputation

0 Neutral

About mattix

  • Rank
    Member

Recent Profile Visitors

364 profile views
  1. Thank you, Barand. This is all new. I'll work on this.
  2. This is the data on the table. id, grpa, grpb 1, 1, 5 2, 4, 6 3, 8, 9 4, 3, 3 5, 5, 4 6, 7, 8 7, 9, 10 8, 10, 5 9, 10, 9 and this the desired table from the original table. I showed the expected table in horizontal view to prevent confusion. My real table is vertical in the code.
  3. I tried this before, it lists all category keys in the html table. It's supposed to list only the category key numbers that matches the value, if not the output to be blank.
  4. yes, this doesn't give error. but it doesn't list the category keys, it lists category values. any ideas there too? if not, thanks anyway.
  5. true. thanks. but even though i made the change you proposed, i still get the same error.
  6. How can I get rid of "Notice:Array to string conversion on line 78" error from this code? can i get a little help please? This is line 78 : $table .= $columnValue; Basically this code's supposed to do is to group the values from grpa, grpb of datatb to 4 different categories according to their value. and as end result, category index number of each category is put into the html table. Thanks. <?php include ("configd.php"); $sql = "SELECT grpa, grpb From datatb"; $result = $conn->query($sql); //categories $cat = [ 4 => [1, 2, 3, 4], 3 => [5, 6], 2 => [7, 8], 1 => [9, 10] ]; while ($row = $result->fetch_assoc()) { foreach ($cat as $catKey => $catValue) { $columns[$catKey] = array_filter($row, function ($col) use ($cat, $catKey) { if (in_array($col, $cat[$catKey])) { return true; } }); } $output[] = $columns; } // the output $table = <<<EOT <table class='maintable'> <tr><th>9:10</th></tr> <tr><th>7:8</th></tr> <tr><th>5:6</th></tr> <tr><th>1:4</th></tr> </table> EOT; foreach ($output as $row) { $table .= "<table class='maintable'>"; foreach ($row as $columnKey => $columnValue) { $table .= "<tr>"; $table .= "<td>"; $table .= $columnValue; $table .= "</td>"; } $table .= "</tr>"; $table .= "</table>"; } echo $table; ?>
  7. Hello, I think this question is a bit of both php and mysql related. I hope I can get some help here. Especially with the mysql part. I have a table like this: CREATE TABLE days ( id INT AUTO_INCREMENT, daya INT, dayb INT, PRIMARY KEY (id) ); INSERT INTO days VALUES (70, 19, 18), (69, 20, 17), (68, 24, 25), (67, 19, 18), (66, 19, 17), (65, 17, 16); and mysql query and php snippet is this: $sql = "SELECT d1.id AS id1, d2.id AS id2, IF((d1.daya-d2.daya)=1,1,0) + IF((d1.daya-d2.dayb)=1,1,0) + IF((d1.dayb-d2.daya)=1,1,0) + IF((d1.dayb-d2.dayb)=1,1,0) AS tcount FROM days AS d1 , days AS d2 WHERE d1.id IS NOT NULL AND d2.id IS NOT NULL AND d1.id > d2.id"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "<tr><td>" . $row["id1"] . "</td><td>". $row["id2"] . "</td><td>" . $row["tcount"]. "</td></tr>"; } echo "</table>"; which gives me a table like this: Id1 Id2 Count 50 49 1 50 48 0 49 48 0 50 47 1 49 47 1 48 47 0 50 46 1 49 46 1 48 46 0 47 46 1 50 45 1 49 45 1 48 45 0 47 45 1 46 45 1 I need to convert the table into this form: id1 goes down the first column, and id2 is in the first row. How can i do this, please? can you give me some help? thank you! id2 49 48 47 46 45 id1 50 1 0 1 1 1 49 0 1 1 1 48 0 0 0 47 1 1 46 1 45
  8. I meant the the code before adding alphabetical listing which I wanted to add later works. Thanks, Barand, I will try your code.
  9. I don't really seek an alternative code, the code works fine, I just can't make it work for the letters.
  10. Here I create monthly html tables for the data. So each month has its own table, and data. Each table has a unique id, and the cells too.
  11. I didn't write this part of code, and I don't have enough knowledge why it's preferred to use there. It assigns unique id's to each table, and unique dbval values to each td element. I'm trying to assign letters to first column instead of numbers which I thought would be a simple thing. but I can't figure out what's wrong here. Basically I want to list letters instead of numbers at the beginning of each row in the first cell.
  12. I’m trying to print letters a-z in the first column with the code below. but for some reason I can’t make it work. (it only prints the first letter “a” down the column). What is it I am doing wrong here? please! Here is the code I'm using: function print_table_tb ($conn, $id) { $sql = "SELECT stata,statb,statc FROM dbA"; $result = $conn->query($sql); if ($result->num_rows > 0) { $range = range('a', 'z'); $i = 0; echo "<table class='tbr' id='tb$id'>"; while($row = $result->fetch_assoc()) { $data = array_reduce($row, function($carry, $value) { $carry[] = "<td dbval='{$value}'>{$value}</td>"; return $carry; }, []); echo '<tr><td class="tbe">'.$range[$i++ % 26].'</td>'. implode('', $data) . "</tr>\n" ; } echo "</table>"; } } The method to lists alphabets here normally works, but i couldn't make it work in this code. I also tried this: function print_table_tb ($conn, $id) { $sql = "SELECT stata,statb,statc FROM dbA"; $result = $conn->query($sql); if ($result->num_rows > 0) { $range = array("a", "b", "c", "d"); $i = 0; echo "<table class='tbr' id='tb$id'>"; while($row = $result->fetch_assoc()) { $data = array_reduce($row, function($carry, $value) { $carry[] = "<td dbval='{$value}'>{$value}</td>"; return $carry; }, []); echo '<tr><td class="tbe">' . $range[$i] . '</td>' . implode('', $data) . "</tr>\n" ; $i++; } echo "</table>"; } } In this code, I also get the same result, can't make it work. any ideas please? thanks.
  13. Thanks for your answer. There are some characters with numbers in the table which sometimes I need them like this, and in this case, i just need the numbers. I'm trying to do two things together here. First is to remove the characters from the data (eg. if it is ".4", then it should be "4"), and after this (or together, I am open to all solutions) I want to filter show null instead of certain numbers (e.g, if my criteria is for "Tnex" is like Tnex<=10, then I would like to show "null" for the values from 1 to 10, and only display the rest of the values.
  14. I have the following piece of code which extracts the data from mysql table. Since some of the data have unwanted characters I use the preg_replace('/[^0-9]+/','',) function to remove them, and only to grab numbers from the rows. I would like to display null in the table cell for certain values like Tnex>=40, Mode>=20 etc. When I tried to do it in sql query with where clause, the rows that don't fit the criteria are not displayed on the table. Instead, I need the rows to be displayed, but just the values to be shown null or empty. For example, in a certain row if "Tnex" >= 40, then the table cell should be null. How can I do this? Thanks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.