Jump to content

forum

Members
  • Posts

    22
  • Joined

  • Last visited

Posts posted by forum

  1. 4 minutes ago, ginerjm said:

    "When you can't do something, don't go to extremes)))) I'm not a programmer yet."

    What is this supposed to mean?   We have been trying to help you but you aren't listening or doing anything that makes sense.  Even your comments don't make sense.  I have never written such detailed simplistic code for anyone before but I did in this topic because I could see that you needed help.  And then you ignored what I said and continued to write bad code.  You said you write shorter code in the beginning.  Well, if you want to accomplish what you set out to do you have to write a BIT MORE CODE than what you thought you could get away with. 

    READ WHAT WE HAVE GIVEN YOU AND AT LEAST TRY IT OUT.  Otherwise I will not try and work with you any longer.

    The answer is clear to me in the code, I just asked for an explanation of the output from the table itself, since the table consists of rows, so I thought that the output would be immediately without a loop))) of course, thanks for writing the code, where I already have an understanding of how to write the code, but what I asked to explain, well, sorry, I want to understand the details, personally at school for 2 years we were never shown the output of the entire table, so I thought it was very simple))

  2. 18 hours ago, ginerjm said:

    Psycho - I would support your decision if you locked this topic.  The OP just doesn't make sense even in his writing and certainly isn't showing any programmer's intelligence.  Never knew of people who played games like you are describing on these forums.

    When you can't do something, don't go to extremes)))) I'm not a programmer yet.

  3. 19 hours ago, Psycho said:

    Programming, like any skills, is a matter of Crawl, Walk, Run. You learn by doing the very simple things, then build on that to learn intermediate skills, then (after a sufficient amount of time) you can learn to do more complex things.

    But, here's the thing. If you already know how to run a query against the database, you should already know how to work with an array and to build an output from it. Plus, the fact that you state you've been working with this language for two years and don't know these fairly easy tasks is incomprehensible to me. In fact, I am leaning towards the fact that you are a troll and just trying to get people mad based on your "not" understanding these things. I've even considered locking the thread.

    Yes, I don’t care what you want to block here, if you can’t clearly explain, then don’t go here with your thoughts, I asked a specific question where I can only agree, but not understand it, or try to explain it so that the student understands, or don't be smart, I personally don't know how to display the entire table, because I thought it was very easy to do.

  4. 11 minutes ago, Psycho said:

    @forum It appears you are of the expectation that when retrieving the results of a Database query, that you should be able to just do an "echo" of the results and have it written to the page in some way. That's not how this works (with PHP/MySQL or any similar languages as far as I know). If you think about this logically, you would understand that would not be very useful for the majority of use cases. Here are just a couple of reasons;

    1. How should the results be formatted? What works for one scenario would not work for the other 9,999 scenarios.
    2. Not all DB queries would be output to the page without other "post-processing". E.g. maybe the results should include sub-totals for different categories, or some records should be displayed differently (e.g. a negative amount in red. It would be extremely difficult if the results were returned in an "echo" ready format to do anything with the data.

    A database returns DATA in a logical data type that a programming language or other resource can work with. It is up to the receiving application to determine what to do with the data. If you want to run a query and have it output to the page in some standard format. Then just create a simple function and you can call that function every time you call a query. That is the beauty of programming, you can write a little bit of code to do something repetitive and reuse that code whenever and wherever you choose. You only have to figure out how to do it one.

    Also, there is a VERY easy way to output a multi-dimensional array in a readable format (albeit not in a table). I do this all the time to be able to debug output from a query.

    $query=$db->query("SELECT * FROM msg");
    echo "<pre>" . print_r($query, TRUE) . "</pre>";

     

    Of course it's possible as you say, but how else can I learn to understand it, for example, I don't write long code when it's confusing for any beginner, I always want to write shorter code in the first steps.

     

  5. 43 minutes ago, ginerjm said:

    You didn't follow what I wrote then.  I specifically told you to use quotes on the array elements which you are not doing.

    And NO - you did not output all the values ... into columns.  There is no html formatting there at all.  How can you even think that you have put anything into a column???

    I think you have more than a php problem.

    I made my post as simple as one can write this exercise in order to help you to follow my explanation as to what you have to do here.  If you can't read it and follow it then I think my work here is wasted.

    I realized that now it’s very difficult to explain to beginners that they understood and remembered the form of writing code, I personally don’t understand this now, maybe when I don’t understand how to write correctly, but it’s all difficult and not clear, for example, as I wrote code, it's a bit clear to me what's going on in the code and it's easier to remember.

  6. 4 minutes ago, ginerjm said:

    Did you Read what I already posted before (or after) you wrote the recent post?  It is not correct.

    And once again I don't understand what you are writing in that last line.

    yes, i read your post, in the last line i output all the values from the table into columns.

  7. 15 minutes ago, ginerjm said:

    Huh? Not sure what you are trying to say.  But - did my last post help at all to make it clearer what and why the code should look like that?

    FYI - If you think that this little exercise is a lot of code you should realize that most php programmers write this kind of code all of the time, surrounded by a lot of other code that creates the data thru manipulation, calculation or concatenation with other data.  This is programming.  And wait until you get to the point that you want to write really fancy looking output and have to learn CSS.  And then add some JS or JQ to add some client-based interactions with the user. 

    That is what you have to look forward to.

    I understand that this is very difficult. I wrote the code as it is clear to me and the result is also there,
    $query=$db->query("SELECT * FROM msg");
    foreach($query as $row){
         echo "$row[id]: $row[msg]: $row[login]: $row[time_msg]<br>";
    }

    although for me it would not suit) but what to do if it was invented to write this php code

  8. 1 hour ago, ginerjm said:

    Actually this last post of the possible code for you is SO simple.  It is using very little PHP and more of HTML.

    1 - Query - the command that runs a query statement to produce the results you want to see

    2 - echo - a statement that sends output to the client

    3 - while - a loop starting statement which allows one to repeatedly process a given set of data.  In this case that data is a result row from the query.  The code included in this loop is wrapped, aka, contained, by a set of braces, ie, {}.

    4 - Fetch - the command that returns one row of the query results to you for processing

    Look up these commands in the manual.  If you don't know how yet, here is the link to the Functions chapter of the manual: 

        https://www.php.net/manual/en/funcref.php

    There is a search box/field in the upper right of the page.  Have at it.  So simple - just three php commands being used.  Now how long can that possible take to learn.  Basically this little block of code runs a query to :

       - collect some data;

       - begin an html table

       - start  loop on the query results that gives the script one row to read at a time

       - the loop code outputs a line of an html table   The table elements (HTML) are <table>, <tr>, <th> and <td>.

       - at the end of the loop the html table is closed.

    The rest of the code is using more echo statements to send the necessary HTML table elements to the client to present the output in a readable format.  I am going out on a limb and stopping here since I hope you understand html.  

    Yes, I know html, but I also thought that I knew PHP, but I decided to display the entire table and it turned out that I don’t know how to do it,))) I thought that I would write the variable into which we make the request in the echo, and that’s all, and then it turned out that not everything is so simple, the brain does not want to perceive what is already in the row table, but they need to be connected through a sampling cycle, so many actions are not clear why, I understood when it was necessary to compare something line by line or something look in the table, but why such difficulties in the usual output here is not yet possible to understand, you just need to agree this is how it should be)

  9. 16 hours ago, Strider64 said:
    $query = $db->query("SELECT * FROM msg");
    
    // Start an HTML table to display the results
    echo "<table>";
    echo "<tr><th>ID</th><th>Message</th><th>Sender</th></tr>";
    
    // Loop through the rows of data and add them to the table
    while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
        echo "<tr>";
        echo "<td>" . $row["id"] . "</td>";
        echo "<td>" . $row["message"] . "</td>";
        echo "<td>" . $row["sender"] . "</td>";
        echo "</tr>";
    }
    
    // Close the HTML table
    echo "</table>";

    This code uses an HTML table to display the query results, with column headings for each field. Inside the while loop, each row of data is output as an HTML table row (<tr>) with cells for each column (<td>). The final echo statement closes the HTML table. Note that this code assumes that the columns in the msg table are named id, message, and sender. If your column names are different, you should update the code to reflect the correct column names.

    Oh, I'm completely confused here, I won't be able to write this for a long time))))

  10. 20 hours ago, ginerjm said:

    1 -  your data is stored in a database table but that doesn't mean it can simply be displayed with something that just "writes it down".  Only records that contain some data values/fields that don't have labels on the pieces that you want to view and which need some code to help make that presentation.

    2 - working with data that has been properly stored in a database table is fairly simple when you know how to use a language to collect it and display it.  It may be called 'complicated' but that is only because it is new to you.   PHP is a fairly easy language to learn and use but it does take some time to read up on and some practice writing it and debugging it until you get the hang of it.

    3 - what is this group of 100 students you are referring to?  I (we?) feel that we are communicating with just one person who may be considered a student who needs to learn a bit about how PHP produces the desired output format, aka, an HTML table.  If one wants to read data from a source and display it in a nice fashion one has to learn how to write the proper commands that will do that.

    4 - complex record?  Records are basically not complex to those who work with them.  You can learn that, although I don't think it is handled by simply writing it down.

    Hope this helps you and your 100 students a bit.

    I always look at the result. This is a language I have been studying for 2 years, and still I don’t understand how many students do some moments, that’s why I ask questions because I don’t understand it,

  11. 2 hours ago, ginerjm said:

    Tables consist of records, or rows.   Each record of a table has a set of fields or data items, also called columns.  A properly designed table makes it easy to search for data based on a properly written query statement.  Once you have created that query and run the query function, you can then write a loop that usually uses a Fetch call to retrieve a single row, outputs or analyzes the data on that row and continues on until there are no rows left to be fetched.

    Do not think of this as any kind of spreadsheet.   Tables are part of a Database.  Spreadsheets are not.   One table can be related to another table and allow you to write queries that gather data from several tables into one result set that gives you pieces of data from that database in a fashion that allows you to do what you need to do with that data.

    But if the table is already created in the database, why complicate the code so much to display the entire table? For example, in a group of 100 students, not a single student understands this complex record and it is not clear how to explain it, it remains to be said, you just need to write it down, of course, it’s stupid, but we don’t understand.

  12. 22 minutes ago, ginerjm said:

    Вы читали что-нибудь о том, как писать php, как выполнять запросы и как отображать результаты? В официальном руководстве по PHP есть несколько хороших примеров, которые сразу же ответили бы на ваш вопрос, если бы вы его прочитали.

    (Совет: вы не можете отобразить массив или результат ресурса из запроса. Вы должны разбить ее на содержимое, которое Barand сделал с помощью функции, но это можно было бы сделать с более подробной информацией, которая могла бы быть вам понятнее.)

    I read, but a lot is not clear, if the database has a table consisting of rows and columns, why renew it into a row. I can’t understand this)) if the table already consists of a row? how can this be understood?

  13. 8 minutes ago, Barand said:

    Самый простой способ - обработать $query как массив и просто перебирать результаты

    <таблица>
        <?php foreaach ($query как $row) {echo "<tr><td>" . Присоединиться("</td><td>", $row) . "</td></tr>";
            }
        ?>
    </table>

     

    somehow you wrote everything confusingly, but why doesn’t it display the entire table as I wrote? because it's clear and simple.

×
×
  • 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.