Jump to content

Need help echoing COUNT(*) in my report


joesoaper

Recommended Posts

The following code is the one I am using. I want to echo the COUNT(model) function in my report, all my attempts have failed  :confused:

 

$result = mysql_query("SELECT model, COUNT(model) AS stockfig FROM inventory WHERE status='In-Stock' GROUP BY model ORDER BY model ASC ");
$num = mysql_num_rows ($result);


if ($num > 0 ) {
$i=0;
while ($i < $num) {


$id = stripslashes(mysql_result($result,$i,"id"));
$model = stripslashes(mysql_result($result,$i,"model"));
$status = stripslashes(mysql_result($result,$i,"status"));

$row .= '
 

 <td>'.$model.'</td>
  <td>'.$status.'</td>
  <td>'.$count.'</td>     
<td><a href="update.php?id='.$id.'">View</a></td>
</tr>';
 
Any help would be greatly appreciated.
Edited by joesoaper
Link to comment
Share on other sites

And "status" should be giving you an error since you didn't select it.

 

Turn on error checking whenever you are writing new code. It helps the process. (See my signature.)

 

Also - Stop using MySQL* functions. If you bother to read the manual, or ever look at it, you'll see a big red box telling that it is outdated and no longer valid in the current PHP version. Better to stop now than have to come back eventually and re-code.

 

Lastly - don't use this method of retrieving row data from a query result. Fetch a whole row and reduce your resource utilization. For example - if you are using MySQL* functions, then use the MySQL_fetch_assoc() to get a whole array of the fieldnames in your query results with only call to the interface instead of 3. Plus you don't have to keep a row counter.

But you should move on to a newer interface - preferably PDO, but that is just my opinion.

Link to comment
Share on other sites

Thanks for the advice taquitosensei at least you have pointed me in the right direction.

 

. As for ever ginerjm and your "bothering" to read the manual, sounds like your attitude needs a big readjustment. I thought people who came here for help were given advice on how to resolve coding problems, however you talk to people like they are idiots and your condescending attitude sucks big time.

 

I am sure when you started coding you knew it all and never had to ask anyone for help because of your "superior attitude" rather than your "superior intellect".

 

Humility is a virtue that you sadly seem to lack.

 

Most probably I will get banned or something equally petty but also maybe someone needs to tell you how it really is, so it will be worth it.

Link to comment
Share on other sites

Sorry to have pointed you in the right direction towards one of the best IT reference manuals in existence. As for adjustments, you seem to need to learn to accept criticism as well as help. I gave you three valid pointers to help you out but you seem to have a problem with being told to read something. Reading is important as any good programmer learns quickly.

Link to comment
Share on other sites

Nice try your attitude still sucks though, do not care how clever you think you are.. sarcasm is a poor teacher as you so ably show, and criticism being given when someone ask for help is just lame

Edited by joesoaper
Link to comment
Share on other sites

"nice try"?

 

My attitude is the same now as it was on my last two posts and will continue to remain the same. If you think I was using sarcasm, apparently you have a hard time recognizing things. Not a good trait in a programmer.

 

I will be sure to pass over your posts in the future.

Link to comment
Share on other sites

@joesoaper:

 

So you want us to be particularly nice to you, and at the same time you're free to insult other members? It doesn't work like this.

 

ginerjm's post is probably the most friendly RTFM you'll ever get. If that's already too much for you, you'll have a hard time getting anywhere in IT. Once you start working with other people – be it professionally or in a hobby project –, your code will be criticized. That's simply how programming works: You write code, and then other programmers review it.

 

Maybe you should just relax and assume that people are here to help you, not attack you.

Link to comment
Share on other sites

Nice try your attitude still sucks though, do not care how clever you think you are.. sarcasm is a poor teacher as you so ably show, and criticism being given when someone ask for help is just lame

 

 

Hi Joe,

 

I read your post, ginerjm's reply to you and the subsequent fallout in the thread.   

 

While perhaps a bit terse, I think you jumped to some conclusions and decided to take offense to what was basically sound advice on a number of different issues. 

 

The mysql_ functions are removed at this point from php.  

 

Using modern api's and bound variables you no longer use stripslashes or string escaping as it is irrelevant.  

 

Certainly you had an issue with your code in terms of the array key naming you would receive, but that is just the start of your problems should you try and run your code against a relatively modern version of php and find it doesn't work.  An update to your host, and existing code that might work at this moment will cease to work from now on.

 

It would be a shame if you decided to ignore an important message, because you felt you were being personally insulted on an internet forum, where everyone is basically anonymous.  The reality is that he was simply stating a fact --- there has been a prominent note in the php manual pages for all the mysql_ functions literally for years now.  Everyone on this site who does a lot of php visits that site regularly, even those of us who have coded php professionally for many years, but we also know that not everyone is aware of just how valuable a resource it is, when people regularly google and grab code snippets from tutorials and articles.  I don't believe that gingerjm attacked you personally, and it would be a mistake in my opinion for you to take it that way.

Link to comment
Share on other sites

Yes well you will see more of my posts. Where I come form terms like  " If you bother to read the manual, or ever look at it " is just being rude and really being sarcastic .. however I have no idea where you all come from. All I did was ask a simple question seeking help... if it is too much to accept a civil reply then maybe this is the wrong forum for newbies. Read the first guys reply.. was amazingly polite and helpful even though he did not just say here is the answer he pointed me in the right direction and I resolved the issue.

 

Maybe The Internet is not for older people like me who grew up showing respect to people no matter where they come from or how they asked what might seem very dumb questions. You all however seem to support his obvious rudeness maybe because he is an "Advanced Member".. which means nothing to me.

 

Thank you again taquitosensei for a very simple polite answer that helped me solve the issue.

 
Link to comment
Share on other sites

You like being the drama queen, do you?

 

ginerjm has provided you with a lot of valuable information beyond your little problem. If you dismiss that just because you think you've detected sarcasm, I'm afraid you're in the wrong forum.

 

We're here to talk about PHP, and your primary concern should be to get accurate information. If you're more interested in meta discussions about the evils of sarcasm, you should probably do that somewhere else.

 

Link to comment
Share on other sites

joesoaper,

 

The problem is that as we keep pointing out, he did not solve your problem, because you are using mysql_ functions, and those are removed from php.  You should either be using mysqli_ or PDO/MySQL instead.

 

Best of luck to you in the future.

Link to comment
Share on other sites

If you read my responses you will see that I am fully open to advice, it is just the manner in which it is delivered. I found a solution as I said and it was through taquito. Upon reading ginerjms's reply I immediately began studying the pdo method and changing the way I code. I might think hes a  sarcastic twit but that does mean I just discounted what he said. I know that I know next to nothing about php coding and can learn from anyone even if I disagree with the method of delivery. I do read and learn from ALL advice.

Link to comment
Share on other sites

If you read my responses you will see that I am fully open to advice, it is just the manner in which it is delivered. I found a solution as I said and it was through taquito. Upon reading ginerjms's reply I immediately began studying the pdo method and changing the way I code. I might think hes a  sarcastic twit but that does mean I just discounted what he said. I know that I know next to nothing about php coding and can learn from anyone even if I disagree with the method of delivery. I do read and learn from ALL advice.

 

 

This is great to hear.   At the end of the day, while ginerjm and other people here might be a bit terse at times, this site exists to help people, and it's great to hear that the advice was received and ultimately it benefitted you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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