Jump to content

How to display the entire table?


forum
Go to solution Solved by ginerjm,

Recommended Posts

@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>";

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

46 minutes ago, forum said:

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.

 

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.

  • Great Answer 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

"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.

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

  • Solution

If the answer is clear to you in the code - Why are we still on this topic?  I have no idea what you have written that makes you happy since you are not sharing anything here.  So why don't you just mark this as solved and end this topic?

 

Link to comment
Share on other sites

  • Psycho locked this topic
Guest
This topic is now closed to further replies.
×
×
  • 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.