[PHP-DB] mysql_num_rows, resource id #

2008-03-27 Thread Richard Dunne
In my code below, I am trying to verify that the query is selecting data from 
both rows of my answers table.  I have run the query on my MySQL CLI and 
getting answers from both rows, but running this script I get $rows = 0.  I 
can't figure out why its not returning 2 for the number of rows.  It is not 
giving me any error msgs such as cannot connect.  

Also can tell me where I can find documentation on resource id #, such as 
resource(5)?
?PHP
DEFINE (host,localhost);
DEFINE (user,root);
DEFINE (password,pasword);
DEFINE (database,questions);

$connection=mysql_connect(host,user,password) or die ('Could not connect' . 
mysql_error() );

$dbConnect=mysql_select_db('questions',$connection);
if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );}

$result = mysql_query(Select answer from answers where 
studentID='A123456789') or die(mysql_error());
$rows = mysql_num_rows($result);
echo $rows;


?


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] mysql_num_rows, resource id #

2008-03-27 Thread Evert Lammerts

Richard Dunne wrote:
In my code below, I am trying to verify that the query is selecting data from both rows of my answers table.  I have run the query on my MySQL CLI and getting answers from both rows, but running this script I get $rows = 0.  I can't figure out why its not returning 2 for the number of rows.  It is not giving me any error msgs such as cannot connect.  


Also can tell me where I can find documentation on resource id #, such as 
resource(5)?
?PHP
DEFINE (host,localhost);
DEFINE (user,root);
DEFINE (password,pasword);
DEFINE (database,questions);

$connection=mysql_connect(host,user,password) or die ('Could not connect' . 
mysql_error() );

$dbConnect=mysql_select_db('questions',$connection);
if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );}

$result = mysql_query(Select answer from answers where 
studentID='A123456789') or die(mysql_error());
$rows = mysql_num_rows($result);
echo $rows;


?

Still no luck then. Try selecting the DB without the connection parameter:

$dbConnect=mysql_select_db('questions');

And don't forget to set error_reporting(E_ALL) above your code.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Fwd: Re: [PHP-DB] mysql_num_rows, resource id #

2008-03-27 Thread Richard Dunne
This much is working:

?PHP
ini_set('error_reporting',E_All);
DEFINE (host,localhost);
DEFINE (user,root);
DEFINE (password,password);
DEFINE (database,questions);

$connection=mysql_connect(host,user,password) or die ('Could not connect' . 
mysql_error() );

$dbConnect=mysql_select_db('questions');
if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );}

$result = mysql_query(Select answer from answers where 
studentID='A123456789') or die(mysql_error());
$rows = mysql_num_rows($result);
echo $rows . \n;
$answer = mysql_fetch_row($result);
foreach($answer as $a)
{
echo $a;
}


?
The output is 
1 
1   
which is correct.

One small step at a time, hopefully forward.

Richard.
---BeginMessage---

Richard Dunne wrote:
In my code below, I am trying to verify that the query is selecting data from both rows of my answers table.  I have run the query on my MySQL CLI and getting answers from both rows, but running this script I get $rows = 0.  I can't figure out why its not returning 2 for the number of rows.  It is not giving me any error msgs such as cannot connect.  


Also can tell me where I can find documentation on resource id #, such as 
resource(5)?
?PHP
DEFINE (host,localhost);
DEFINE (user,root);
DEFINE (password,pasword);
DEFINE (database,questions);

$connection=mysql_connect(host,user,password) or die ('Could not connect' . 
mysql_error() );

$dbConnect=mysql_select_db('questions',$connection);
if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );}

$result = mysql_query(Select answer from answers where 
studentID='A123456789') or die(mysql_error());
$rows = mysql_num_rows($result);
echo $rows;


?

Still no luck then. Try selecting the DB without the connection parameter:

$dbConnect=mysql_select_db('questions');

And don't forget to set error_reporting(E_ALL) above your code.

---End Message---
-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DB] Not updating certain fields in same row

2008-03-27 Thread Jason Pruim

Hi Everyone

Thanks for all the info and help with this, I have decided to write a  
separate function for changing the password. That way I can compare  
the original password with the one inputted in the database, and then  
change it after both have been the old and new password have been  
verified :)


So Thanks! :)



On Mar 25, 2008, at 12:59 PM, Jason Pruim wrote:

Hi everyone,

I am attempting to update a record for a login system while leaving  
certain fields untouched if they arn't changed, and am running into  
issues.


Basically what I want to do, is say I have these fields:

Field1
Field2
Field3
Field4

I update Field1 and Field3 but not Field2 and Field4. What I want to  
do is change the values in Field1 and Field3 without touching the  
values in Field2 and Field4.


I have tried this code:
$tab = \t;
	if (!isset($_POST['txtLoginName']) ||  
empty($_POST['txtLoginName'])) {


			$loginName = mysqli_real_escape_string($chpwpostlink,  
$_POST['txtLoginName']);

}
else
{
$loginName = $tab;
}

which works the fields that I've changed, but if I don't submit a  
value in the form it sets the field to be blank in MySQL. Which is  
what I am trying to avoid. Any ideas?


--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
[EMAIL PROTECTED]





--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
[EMAIL PROTECTED]




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Resource id #5

2008-03-27 Thread Richard Dunne
Can someone explain how I can translate Resource id #5 which is what I am 
getting from the code below?  

$result = mysql_query(Select answer from answers) or die(mysql_error());
$resultArray = explode(',',$result);
for ($i=0;$isizeof($resultArray);$i++)
{
echo $resultArray[$i];
}



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Resource id #5

2008-03-27 Thread Miguel Guirao
Been a positive integer, it jeans that the SQL query was succesfully
executed, read the function description. 

__
Miguel Guirao Aguilera, Linux+, ITIL
Sistemas de Información
Informática R8
Ext. 7540

-- -Original Message-
-- From: Richard Dunne [mailto:[EMAIL PROTECTED]
-- Sent: Thursday, March 27, 2008 11:51 AM
-- To: php-db@lists.php.net
-- Subject: [PHP-DB] Resource id #5
-- 
-- Can someone explain how I can translate Resource id #5 which is what I
-- am getting from the code below?
-- 
-- $result = mysql_query(Select answer from answers) or
-- die(mysql_error());
-- $resultArray = explode(',',$result);
-- for ($i=0;$isizeof($resultArray);$i++)
-- {
-- echo $resultArray[$i];
-- }
-- 
-- 
-- 
-- --
-- PHP Database Mailing List (http://www.php.net/)
-- To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Resource id #5

2008-03-27 Thread Stut

On 27 Mar 2008, at 17:51, Richard Dunne wrote:
Can someone explain how I can translate Resource id #5 which is what  
I am getting from the code below?


$result = mysql_query(Select answer from answers) or  
die(mysql_error());

$resultArray = explode(',',$result);
for ($i=0;$isizeof($resultArray);$i++)
{
echo $resultArray[$i];
}


For the love of $DEITY, please read the frickin' manual: http://php.net/mysql 
. You've been asking similar questions around this topic for the past  
few days and you clearly haven't moved forward in your understanding.


The mysql_query function returns a resource. If you print a resource  
you get the text Resource id #n where n is replaced with its ID. To  
make use of this resource you need to use functions like  
mysql_fetch_array, mysql_fetch_assoc or one of the many others  
detailed in, you guessed it, the manual. Try it, you might like it.


-Stut

--
http://stut.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Table optimization ideas needed

2008-03-27 Thread Shelley
On Thu, Mar 27, 2008 at 1:55 PM, Chris [EMAIL PROTECTED] wrote:

 Good idea. But I wonder whether calling the trigger each insert will loose
  any performance.
 

 It's going to affect things slightly but whether it'll be noticable only
 you can answer by testing.

 Another option I sometimes see is set up a replicated slave and run your
 reports off that instead of the live system, then:

 1) it won't bog the live db down
 2) it doesn't really matter how many queries you run
 3) it doesn't really matter how long they take to run


Hm... This makes sense.  :)

I indeed have several slaves running.

Great. Thank you.


Thank you for all your help.



 --
 Postgresql  php tutorials
 http://www.designmagick.com/




-- 
Regards,
Shelley