Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

mysql wont display first row

Codes here !

Moderators: macek, egami, gesf

mysql wont display first row

Postby pzaz » Fri Mar 21, 2003 6:34 pm

hello all -
I am using mysql and php to generate a navigation bar for a site I'm working on. I set up the table with the following fields -

id tinyint(2) auto-increment primary
link varchar(150)
position tinyint(2) unique - this determines the position of a link in the navbar
display tinyint(1) - this is to determine if a link is displayed in the navbar or not

the php that generates the navbar looks like this -

function displayNav($result)
{
// Until there are no rows in the result set,
// fetch a row into the $row array and
while ($row = @ mysql_fetch_row($result))
{
for($x=1; $x<9; $x++)
{
$link=mysql_fetch_object($result);
echo $link->horizLink . " | ";
}
;
}
}

$query = "SELECT * FROM topNav WHERE display=1 ORDER BY position";

// Connect to the MySQL server
require_once('../Connections/connect.php');

if (!(mysql_select_db("rbos", $connect)))
showerror();

// Run the query on the connection
if (!($result = @ mysql_query ($query, $connect)))
showerror();

// Display the results
displayNav($result);

and for some reason it wont show the first row, so my navbar is missing the first link - "introduction" in this case.

things I've done so far -
-when I changed the id of the introduction row from 1 to 11,
same result, the second item, "about" appears first but no "introduction".
-when I deleted the "introduction" row from the topNav table, the original second item, "about", was missing and the third menu item appeared first.
-I replaced the introduction row and changed the position numbers of each of the menu items so that the list of items started at 2 instead of 1. So at this point, the introduction row is id 15 (because it went to the end of the list when I replaced it) and position 2 (so it would appear first in the nav bar.) The results were the same as when it was position 1 - no introduction link in the nav bar.
- when I removed the ORDER BY from the select statement, "introduction" appeared as the last item in the navigation but the second item, "about" was missing with the third menu item appearing first.

It seems like something simple, but I'm not getting it.
I'm hoping that someone out there is wiser than me and they will be kind enough to explain what I have over looked.

thanks in advance :)
David
pzaz
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue Feb 18, 2003 4:47 pm
Location: Los Angeles, CA

a quick fix...

Postby pzaz » Sat Mar 22, 2003 12:30 pm

I still don't understand this behavior, but I solved it by simply duplicating the "introduction" row and putting it right before the first one. This works - I get a complete nav bar, even though there are actually two identical rows, IDs 1 & 2.

most peculiar :roll:
pzaz
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue Feb 18, 2003 4:47 pm
Location: Los Angeles, CA


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.