Jump to content

Recommended Posts

Well i'm working on creating a forum, and so I'm playing around with getting my category listing as a starter towards the rest of the hell i'm creating.

 

Anyways  :)

 

My problem is it will skip the first row, and I've got no idea why.

 

Some insight would be nice, and any coding practice errors I've made can surely be pointed out as well. I welcome the criticism, it helps in the end.

 

My Table:

ID     category_title      sub_categories
1      News                  Announcements~Updates~Worklog
2      Other                  Spam~Spam~Spaaaaam!
3      placehold             ugh~what~no

 

My Code:

<?php
function retrieve_forums(){
// Lets start by starting the first level of display with the category
$get_category =	"SELECT * FROM `category` ORDER BY `ID`";
$resulting_categories = mysql_query($get_category) or die("wtfx: <br />".mysql_error());
// build an array of category and create sub-categories under
if (mysql_fetch_row($resulting_categories)==0){
	die("You need to create main categories....");
}
else {
	while($category_row = mysql_fetch_array($resulting_categories)){
		echo $category_row['category_title'] . "<br />";
	}
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/147593-solved-first-row-skipped-confused/
Share on other sites

mysql_fetch_row($resulting_categories)==0

 

with this statement, you throw your first category out into nothingness ;)

 

use mysql_num_rows instead ;)

 

<?php
function retrieve_forums(){
// Lets start by starting the first level of display with the category
$get_category =	"SELECT * FROM `category` ORDER BY `ID`";
$resulting_categories = mysql_query($get_category) or die("wtfx: <br />".mysql_error());
// build an array of category and create sub-categories under
if (mysql_num_rows()==0){
	die("You need to create main categories....");
}
else {
	while($category_row = mysql_fetch_array($resulting_categories)){
		echo $category_row['category_title'] . "<br />";
	}
}
}
?>

Interesting. I don't remember that happening before though, but I havent touched mysql in many months, I've only worked on stuff with api's for their statements.

 

Thanks, I feel stupid but I'll remember it, at least till I forget it, but hopefully it will click.

;)

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.