Jump to content

can anyone see a problem with this query ?


jamesxg1

Recommended Posts

Hi Everyone!

 

Can anyone see a problem with this query, it is part of a class by the way.

$this->getNewIID = "SELECT `replyid`, `id` FROM `answers` ORDER BY `replyid` DESC LIMIT 1";
$this->runGetNewIID = mysql_query($this->getNewIID);

while($this->newIID = mysql_fetch_assoc($this->runGetNewIID)):
$this->iid = $this->newIID['id'] + 1;
endwhile;

Many thanks

 

James.

Link to comment
Share on other sites

James,

  No offense intended here, but I don't see the value of what you are doing with classes.  It's great you are trying to use them, but it seems you are simply substituting member variables in a class where you could otherwise use temporary variables.  There's no value in your example, to using a class variable to store a result set. 

 

With that said I don't see an obvious problem with your query syntax.  Nevertheless you should check the value of the result returned from mysql_query().  We don't know what your table definition is, but any issue there in naming of columns could cause an error.  At very least you should:

 


if ($this->runGetNewIID) {
  //Got a result, go ahead and fetch in a loop.
} else {
  // check mysql_error()
}

Link to comment
Share on other sites

Hi!

 

None taken the way I see it is if your doing it wrong you must be told lol!. And being told by someone who knows what there doing is all the better. Thank you for the advice due to this I have fixed the problem :).

 

Many thanks

 

James.

Link to comment
Share on other sites

Hi!

 

None taken the way I see it is if your doing it wrong you must be told lol!. And being told by someone who knows what there doing is all the better. Thank you for the advice due to this I have fixed the problem :).

 

Many thanks

 

James.

 

Glad to have helped, and great attitude.  +1 for you -- being open to constructive criticism is important for any programmer.  Even though I'm an old salt I always learn things from working with other programmers on projects.

 

FWIW, there's what I consider to be some excellent examples of Design pattern driven OOP design in the Zend framework.  Take a look at some other their classes and try and understand what they're doing.  Learning from the example of others is usually very effective.

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.