EDIT: Solved.
Still, though, I'm curious as to what changed about the code below. It turns out it was something else, at least something else that fixed it, but I wonder what this code has to do with it...
But... all better... so no big deal.
Maybe you can just tell me the below code is definitely right and something else must have been wrong, in which case, it must've for a while... maybe I just overlooked it.
If you're wondering what solved it, I had a if ($var > 0), but it needed to be if ($var > -1), because it changed after the if... I think you know what I mean.
Anyway... weird. Didn't remember changing that recently.
[/EDIT]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
I'm coding a pretty complex page that I'm actually using as a search engine. This part of the code grabs all the possible results, puts the values from the database of "type", "name", "keywords", etc. into variables that are named according to the name of the item... but that's getting a bit deeper than is relevant to the problem.
Basically, at the moment, there are 14 rows in my database.
It used to work fine, but today I changed a couple things, and now it doesn't work.
What I changed seemed trivial... the name of the table in the db, the name of a column or two, and what columns it would get... just wanted to change it around a bit...
Now, when the script runs, it only gets the last 13 of the 14 rows. They're perfect, but there's no trace of the 1st row. It does the same thing each time, always the same row.
So... can someone tell me what's going wrong here?
A couple notes:
1. I'd be happy to show you the rest of the code, but it's 351 lines (and growing), and the rest isn't relevant to this, I don't think.
2. In the code below, you can probably just ignore the content of the while loop... that's just setting up the variables for later... works fine, at least according to the 13 that do work, but I don't think that's what's stopping the 1st result from being loaded.
3. There are ways to code around this, but this is a pretty important part of the script, so I'd like it to work the best way possible, not just find som weird way around the error, like coding an extra loop in there just for the first result or whatever.
PHP Code:
$namenum = 1;
$query = 'SELECT `name`, `type`, `keywords`, `title`, `description` FROM `stockpile_items`';
$result = mysql_query($query) or die('Cannot get data.'.mysql_error());
while ($row = mysql_fetch_assoc($result)) {
$name = $row["name"];
$ntype = $row["type"];
$keywords = $row["keywords"];
$title = $row["title"];
$description = $row["description"];
$content = '<a href="index.php?act=view&item='.$name.'">'.$title.'</a><br>'.$description.'<br><br>';
$namevar = "names$namenum"; $$namevar = $name; $namenum++;
$ntypename = "ntype$name"; $$ntypename = $ntype;
$keywordsname = "keywords$name"; $$keywordsname = $keywords;
$contentname = "content$name"; $$contentname = $content;
}
As for the page this is all going onto, you can view it here:
http://thebrb.com/stockpile/fix/index.php?act=search
Just click "search" without typing anything in, leaving the catergory as "all", and all the results will be displayed...
note: the page is complex, and has other stuff going on... so stay within the search options, but if you get out, just use the navbar to your left to get back.
Anyway, working on this... might figure it out soon. In that case, I'll post here so you don't waste your time... but this has had me stumped all day, so not expecting to figure it out anytime soon.
EDIT: Just tested to be sure that it was an issue during that loop. It is. I put a var there, and had it add one each cycle, then echo. It counted from 1-13.
Does the mysql_fetch_assoc() operate in reverse, meaning it's not getting BACK to the first one? Or it's skipping the first one right off?
Bookmarks