Jump to content

newb: Simple MySQL Query


doofy

Recommended Posts

The following query or while loop is only increasing the ArticleID variable every 3rd time the script is run, I've narrowed it down to the following code snippet. Can you spot a problem with this, I'm in my first week of PHP and MySQL and I can't see any problem with it.

 

Any help would be mighty appreciated by this idiot  :D

 

Code snippet:

---

$result = mysql_query("SELECT ArticleID FROM test_top ORDER BY ArticleID ASC LIMIT 1") or die(mysql_error()); 

while($row = mysql_fetch_array($result))

{

$ArticleID=$row['ArticleID'];

}

$ArticleID=intval($ArticleID);

$ArticleID++;

---

 

Link to comment
Share on other sites

I'm trying to post a variable over url to identify an article id. I've got a template that will pull the data from the database based on this ArticleID. This section is at the admin's "Article Submission" point, so I want to see what the last ArticleID was from the test_top table and increase it by one.

 

Thanks man,

Chris

Link to comment
Share on other sites

Does the code look okay anyways, it's not doing what I intended, I was expecting it to see the last (highest value) of the variable, and increase it by one for preparation to the database.

 

There is nothing wrong with the code with regard to syntax, but as Pikachu2000 stated it really doesn't make sense for what you seem to be wanting to accomplish.

 

However, I will state that there are issues witht hat code aside from syntax and purpose.

 

1. If you are using LIMIT 1 on the query why are you using a while loop.

2. Why extract the value and then add 1, just add 1 in the query.

 

$query = "SELECT ArticleID + 1 FROM test_top ORDER BY ArticleID ASC LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
$ArticleID = result($result, 0);

 

But, really, what you are doing just doesn't make sense.

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.