Current location: Hot Scripts Forums » Programming Languages » PHP » first row in DB query not showing up


first row in DB query not showing up

Reply
  #1 (permalink)  
Old 01-08-04, 02:05 PM
lordmerlin lordmerlin is offline
Newbie Coder
 
Join Date: Jul 2003
Location: South Africa
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
first row in DB query not showing up

Hi my fellow developers & coders

I run the following command, and the first row doesn't show up. The $num_domain_rows shows 4, yet the while loop only displays 3, why would this be?

PHP Code:

[color=#ffffff]$domain_result = mysql_query ("SELECT * FROM domain_accounts WHERE activated='0'") or die (print mysql_error()); 
$num_domain_rows=mysql_num_rows($domain_result);
$domain_row mysql_fetch_array($domain_result);[/color]
[
color=#ffffff]if ($num_domain_rows > 0) {  
 
while($row mysql_fetch_array($domain_result)){ 
    print 
'Domain id '.$row[id].'<br>';
 }
}
[/
color
Reply With Quote
  #2 (permalink)  
Old 01-09-04, 09:51 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
first of all you needn't to call the results twice !!
like you fetched them here :
Quote:
PHP Code:

$domain_row mysql_fetch_array($domain_result);

$row mysql_fetch_array($domain_result); 
it's only showing 3 results becasue you fetched the info twice !!
in first time it wasn't printed and that when you used :
$domain_row = mysql_fetch_array($domain_result);
then it's calling the next result in the loop using $row .. that's why!!
just remove the var $domain_row and it will work fine , your code after changes should look like this :
PHP Code:

$domain_result mysql_query ("SELECT * FROM domain_accounts WHERE activated='0'") or die (print mysql_error()); 


$num_domain_rows=mysql_num_rows($domain_result);

if (
$num_domain_rows 0) {  
while(
$row mysql_fetch_array($domain_result)){ 
    print 
'Domain id '.$row[id].'<br>';
}

btw why are you using the white color ? it's not clear to read ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 01-09-04, 11:43 AM
lordmerlin lordmerlin is offline
Newbie Coder
 
Join Date: Jul 2003
Location: South Africa
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Thanx, I didn't think of that, you were a great help.

The white is only the table bacground color

Quote:
Originally Posted by NeverMind
first of all you needn't to call the results twice !!
Reply With Quote
  #4 (permalink)  
Old 01-09-04, 11:53 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
btw I figured that you have another error
you shouldn't use print inside die() !! because die will print the parameter passed to it automaticly !
so this how the first line should look :
PHP Code:

 $domain_result mysql_query ("SELECT * FROM domain_accounts WHERE activated='0'")or die(mysql_error()); 

__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #5 (permalink)  
Old 01-09-04, 12:28 PM
lordmerlin lordmerlin is offline
Newbie Coder
 
Join Date: Jul 2003
Location: South Africa
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Thanx for this tip as well. Now I need to update quite a few files, but this would be a breeze with dreamweaver, since I can do batch find / replaces
Reply With Quote
  #6 (permalink)  
Old 01-09-04, 12:34 PM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
I didn't know you can do that. You can change a whole batch?
Reply With Quote
  #7 (permalink)  
Old 01-09-04, 12:58 PM
lordmerlin lordmerlin is offline
Newbie Coder
 
Join Date: Jul 2003
Location: South Africa
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Yup


Use the search and replace fucntion with ctrl+F, add the text to search, and the text to replace, and under "Find in", choose which files / folders to use, you can even tell it to use the whole current site, as well as wether is should look in the source or the document text, if it's in normail HTML
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
Trouble with query coolblu PHP 1 12-17-03 12:47 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
Syntax error (missing operator) in query expression crobinson ASP 4 11-23-03 08:49 PM
Show query results by in a different way mdhall PHP 4 11-09-03 11:18 AM


All times are GMT -5. The time now is 08:23 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.