Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Recommended way to get TOTAL FIELDS
Old 02-12-2009, 12:58 AM Recommended way to get TOTAL FIELDS
Experienced Talker

Posts: 38
Name: carl
Trades: 0
ok, here is the deal. I have a php script I am using in the header of my wordpressMU powered site. For some reason the script is pissing the signup page off, the script works fine but the signup page does not as long as the script is run. Anyway I have a seperate database (other than the one used by Wordpress) in which I store profile information. I want to be able do display the TOTAL NUMBER OF PROFILES (rows) in the database...which this script does, but I need to do it some other way that will not interfere with Wordpress/Buddypress signup page. Here is the script...any workarounds or other ways to get this information?

<?php

include "logininfo.php";

$result = mysql_query("SELECT count * as total_record FROM contacts");

$num_rows = mysql_num_rows($result);

echo $num_rows;

mysql_close();

?>
Exbrief is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-12-2009, 06:51 AM Re: Recommended way to get TOTAL FIELDS
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Write the other databases files to a file, then include that file.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 02-12-2009, 07:19 AM Re: Recommended way to get TOTAL FIELDS
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
PHP Code:
<?php
include "logininfo.php";
$result mysql_query("SELECT count * as total_record FROM contacts");
$num_rows mysql_num_rows($result);
echo 
$num_rows;
mysql_close();
?>
Nope...
Using select count, you get 1 row, with 1 column that hold the count value.
And by the way, count being a sql function, it's
Code:
select count(*)
mysql_num_rows will tell you that you have 1 row, but it will not be the total.

You actually must parse the result dataset:
PHP Code:
<?php
include "logininfo.php";
$result mysql_query("SELECT count(*) as total_record FROM contacts");
while(
$o=msql_fetch_object($result)){
  
$cnt=$o->total_record;
}
echo 
$cnt;
mysql_close();
?>
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 02-12-2009 at 07:21 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-12-2009, 11:49 AM Re: Recommended way to get TOTAL FIELDS
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
And you do not need the while loop either, since there will be only one row in the result. Just to be sure, you can also add a LIMIT clause. So
PHP Code:
 <?php
include "logininfo.php";
$result mysql_query("SELECT count(*) as total_record FROM contacts LIMIT 1");
$o=mysql_fetch_object($result);
$cnt=$o->total_record;
echo 
$cnt;
mysql_close();
?>
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 02-12-2009, 12:25 PM Re: Recommended way to get TOTAL FIELDS
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
And you do not need the while loop either
That's me being lazy.
I have one snippet, and I always use the while loop, even when I know there should only be 1 row...

But Mattias is right, no need for a loop here.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-12-2009, 02:58 PM Re: Recommended way to get TOTAL FIELDS
Experienced Talker

Posts: 38
Name: carl
Trades: 0
Quote:
Originally Posted by lizciz View Post
And you do not need the while loop either, since there will be only one row in the result. Just to be sure, you can also add a LIMIT clause. So
PHP Code:
 <?php
include "logininfo.php";
$result mysql_query("SELECT count(*) as total_record FROM contacts LIMIT 1");
$o=mysql_fetch_object($result);
$cnt=$o->total_record;
echo 
$cnt;
mysql_close();
?>

so if I use this script then I will get the total # of rows in the table, whether they are added or deleted, correct?

aLso, this is the original script I was using, and it worked well, but it was causing problems with the login page on my wordpress powered site.

<?php

include "logininfo.php";

$result = mysql_query("SELECT * FROM contacts");

$num_rows = mysql_num_rows($result);

echo $num_rows;

mysql_close();

?>

Last edited by Exbrief; 02-12-2009 at 02:59 PM..
Exbrief is offline
Reply With Quote
View Public Profile
 
Old 02-12-2009, 03:01 PM Re: Recommended way to get TOTAL FIELDS
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
The difference between the 2 is that the first one ask the db to give the number of rows, where the seconds ask the db to send all the rows, and count how many there where.

On a technical view, the second solution is wasting server time.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-12-2009, 03:31 PM Re: Recommended way to get TOTAL FIELDS
Experienced Talker

Posts: 38
Name: carl
Trades: 0
ok, thanks everyone. I have a question, maybe someone will know the answer to and I have ben searching for over a month and asked everyone I can think of. Im going nuts with htis.

My site is powered by WordpressMU, and Buddypress. Each web page calls the header and footer (header.php and footer.php). In the header I have the script mentioned above. For some reason the signup page (wp-signup.php, which calls header.php) is missing the "Full Name" field...take the script out...no issue. Any idea why this is happening and how to make it work?
Exbrief is offline
Reply With Quote
View Public Profile
 
Old 02-12-2009, 05:24 PM Re: Recommended way to get TOTAL FIELDS
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Unless someone here is very familiar with WordpressMU (I don't evan know what it is) you have given way too little information. All you said was basically "if I call this script it messes up that script". Could you perhaps post some of the code from the signup and/or header file? (Im quessing they have alot of code in them, if so please don't post all of it. Try to find the relative parts.)
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 02-13-2009, 02:11 PM Re: Recommended way to get TOTAL FIELDS
Skilled Talker

Posts: 79
Location: Devon, England
Trades: 0
There's not much information to go by but it sounds like a full name textbox is missing in the sign up page. I also take it that you wrote or edited the header.php file so it's branded.

If that is the problem it looks like you may have some unclosed html tags causing some of the signup page to render incorrectly.

This is just a stab in the dark guess really as we would need a little more info.
__________________
Please add to my Talkupation if I was helpful. Thanks.


Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
paaaaaaaaaa is offline
Reply With Quote
View Public Profile Visit paaaaaaaaaa's homepage!
 
Old 02-13-2009, 03:52 PM Re: Recommended way to get TOTAL FIELDS
Experienced Talker

Posts: 38
Name: carl
Trades: 0
i didnt write the code for the header to answer that question, I just added this script above. There is a lot of code, I will paste the header.php cpde the way I have it now.

Also, by messing up the signup page I mean, when my script is not in the website at all there is a field to fill out to create a an account called "Full Name"....this is on the signup.php file, which calls the header.php as explained above. When I put the script on the header the "Full Name" field disappears. Here is the site so you get a better idea of what all this looks like. My script is not in there currently so you can click on "sign Up" and see the Full NAme field.

www.ex-brief.com


HEADER.PHP CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

<title><?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> &raquo; Blog Archive <?php } ?> <?php wp_title(); ?></title>

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />

<style type="text/css" media="screen">

<?php
// Checks to see whether it needs a sidebar or not
if ( !empty($withcomments) && !is_single() ) {
?>
#page { background: url("<?php bloginfo('stylesheet_directory'); ?>/images/kubrickbg-<?php bloginfo('text_direction'); ?>.jpg") repeat-y top; border: none; }
<?php } else { // No sidebar ?>
#page { background: url("<?php bloginfo('stylesheet_directory'); ?>/images/kubrickbgwide.png") repeat-y top; border: none; }
<?php } ?>

</style>

<?php wp_head(); ?>
</head>
<body>
<div id="page">


<div id="header" onclick="location.href='http://ex-brief.com/';" style="cursor: pointer;">
<div id="headerimg">
<h1><br /><br /><?php
$stats = get_sitestats();
echo "".$stats[ 'users' ]." Members";
?><br />

<?php

include "logininfo.php";

$result = mysql_query("SELECT * FROM contacts");

$num_rows = mysql_num_rows($result);

echo $num_rows;

mysql_close();

?>

ExBriefs

</h1>
<div class="description"><?php bloginfo('description'); ?></div>
</div>
</div>
<hr />

Last edited by Exbrief; 02-13-2009 at 03:57 PM..
Exbrief is offline
Reply With Quote
View Public Profile
 
Old 02-16-2009, 03:54 PM Re: Recommended way to get TOTAL FIELDS
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Could you perhaps also give a link to the site where your code is included, so we can see it without the username text field (still leaving the working one up, so we can compare the two)?
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 02-18-2009, 04:45 PM Re: Recommended way to get TOTAL FIELDS
Experienced Talker

Posts: 38
Name: carl
Trades: 0
i dont have this in 2 places unfortunately, so I can not do that exactly. What I can do is put the code back in then you can go to the signup page and see the difference. Will that work?
Exbrief is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Recommended way to get TOTAL FIELDS
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.69335 seconds with 12 queries