php db insert messed up...<

windows

Guest
*Edit: Sorry, I didn't notice the forum specifically for PHP discussions.

Hi,

I'm having a problem with data entry into my mysql db.

You can see what's going on here:

<!-- m --><a class="postlink" href="http://www.brokenlands.com/phptest/">http://www.brokenlands.com/phptest/</a><!-- m -->

Now, the posting, editing and deleting works fine (there's no user sign-up or anything so anyone is able to access all the functions).

The thing is though, if I delete a post, and then add a new one, the new one will be added into the spot of the deleted post instead of to the bottom of the table. I'm not sure what's going on...

The fields in my table are:

newsId (pk, int, auto increment)
postedDate
author
newsTitle
news

Now this is how I insert the data:

$sqlQuery="INSERT $table SET postedDate='$postedDate', author='$author', newsTitle='$newsTitle', news='$news'";

And this is how I remove it:

$sqlQuery="DELETE FROM $table WHERE newsId = '$newsId'";

Any idea what's wrong?someone want to move this thread to PHP sub forum?Originally posted by afterburn
someone want to move this thread to PHP sub forum?

...not really....but I will because I spoil ya :POriginally posted by Validus
*Edit: Sorry, I didn't notice the forum specifically for PHP discussions.

Don't worry, happens ALL the time. :DI should probably add that I used this to execute the queries:

$results = mysql_query($sqlQuery);

I played around with this bug of mine a bit more, and I notice that if I optimize the table after deleting a row, a new post will appear at the bottom as it should.

(I used phpMyAdmin to optimize the table.)

I'm no good at PHP. I actually just started learning it today... My wild, and probably wrong, guess is that when I delete a row through my code, I just remove the data, but I don't actually get rid of the row? So then when I add some new data, it throws it into that empty row for efficiency reasons?

I'll stop guessing now...

Would there maybe be a way to optimize the table after I delete a row through the code? Or maybe actually a way to completely delete the row?The order the info is in in your db doesn't matter. It seems you've used some sort of auto incremented id which is good. It seems to me that the problem isn't in where the data is located, but in your query when you grab the data out of the db.

try adding something like this in your query

select * From $table order by news_ID descOh, well of course. Thanks, that did it.
 
Back
Top