Getting a recordcount

This is a discussion on Getting a recordcount within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi I have opened a database in PHP and would like to know whether a particular record exists. i.e. $...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-29-2003
Andy Levy
 
Posts: n/a
Default Getting a recordcount

Hi

I have opened a database in PHP and would like to know whether a particular
record exists.

i.e.

$ThisUsername = $_REQUEST['Username'];
mysql_pconnect("myHost","myLogin","myPass");
mysql_select_db("myDB");

$result = mysql_query("SELECT * FROM users WHERE Username = $ThisUsername");

This should generate a 1 Record recordset. How can i test if the recordset
only contains 1 record.

Thanks

Andy L


Reply With Quote
  #2 (permalink)  
Old 10-29-2003
Tom Thackrey
 
Posts: n/a
Default Re: Getting a recordcount


On 28-Oct-2003, "Andy Levy" <andy_levy@hotmail.com> wrote:

> I have opened a database in PHP and would like to know whether a
> particular
> record exists.
>
> i.e.
>
> $ThisUsername = $_REQUEST['Username'];
> mysql_pconnect("myHost","myLogin","myPass");
> mysql_select_db("myDB");
>
> $result = mysql_query("SELECT * FROM users WHERE Username =
> $ThisUsername");
>
> This should generate a 1 Record recordset. How can i test if the
> recordset
> only contains 1 record.




http://www.php.net/manual/en/functio...l-num-rows.php

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)
Reply With Quote
  #3 (permalink)  
Old 10-29-2003
Michel
 
Posts: n/a
Default Re: Getting a recordcount

if(mysql_num_rows($result)==1)echo "only one record";

Greetz,

Mich

"Andy Levy" <andy_levy@hotmail.com> wrote in message
news:FOHnb.1895$0E5.667@news-binary.blueyonder.co.uk...
> Hi
>
> I have opened a database in PHP and would like to know whether a

particular
> record exists.
>
> i.e.
>
> $ThisUsername = $_REQUEST['Username'];
> mysql_pconnect("myHost","myLogin","myPass");
> mysql_select_db("myDB");
>
> $result = mysql_query("SELECT * FROM users WHERE Username =

$ThisUsername");
>
> This should generate a 1 Record recordset. How can i test if the

recordset
> only contains 1 record.
>
> Thanks
>
> Andy L
>
>



Reply With Quote
  #4 (permalink)  
Old 10-29-2003
Floris van den Berg
 
Posts: n/a
Default Re: Getting a recordcount

[sorry for the bottomquote, everyone in this thread seems to be doing it so
at least i'm consistent]

or:

$result = mysql_query("SELECT COUNT(*) FROM users WHERE
Username=$thisusername", $db);
$row = mysql_fetch_row($result);
if ($row[0] == 1) echo "only one record";

Floris

"Michel" <please_no@spam.nl> schreef in bericht
news:bnnlli$jce$1@news.cistron.nl...
> if(mysql_num_rows($result)==1)echo "only one record";
>
> Greetz,
>
> Mich
>
> "Andy Levy" <andy_levy@hotmail.com> wrote in message
> news:FOHnb.1895$0E5.667@news-binary.blueyonder.co.uk...
> > Hi
> >
> > I have opened a database in PHP and would like to know whether a

> particular
> > record exists.
> >
> > i.e.
> >
> > $ThisUsername = $_REQUEST['Username'];
> > mysql_pconnect("myHost","myLogin","myPass");
> > mysql_select_db("myDB");
> >
> > $result = mysql_query("SELECT * FROM users WHERE Username =

> $ThisUsername");
> >
> > This should generate a 1 Record recordset. How can i test if the

> recordset
> > only contains 1 record.
> >
> > Thanks
> >
> > Andy L
> >
> >

>
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:01 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0