Professional Web Applications Themes

Getting a recordcount - PHP Development

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...

  1. #1

    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


    Andy Levy Guest

  2. #2

    Default Re: Getting a recordcount


    On 28-Oct-2003, "Andy Levy" <andy_levyhotmail.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.


    [url]http://www.php.net/manual/en/function.mysql-num-rows.php[/url]

    --
    Tom Thackrey
    [url]www.creative-light.com[/url]
    tom (at) creative (dash) light (dot) com
    do NOT send email to [email]jamesbutlerwillglen.net[/email] (it's reserved for spammers)
    Tom Thackrey Guest

  3. #3

    Default Re: Getting a recordcount

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

    Greetz,

    Mich

    "Andy Levy" <andy_levyhotmail.com> wrote in message
    news:FOHnb.1895$0E5.667news-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
    >
    >

    Michel Guest

  4. #4

    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_nospam.nl> schreef in bericht
    news:bnnlli$jce$1news.cistron.nl...
    > if(mysql_num_rows($result)==1)echo "only one record";
    >
    > Greetz,
    >
    > Mich
    >
    > "Andy Levy" <andy_levyhotmail.com> wrote in message
    > news:FOHnb.1895$0E5.667news-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
    > >
    > >
    >
    >

    Floris van den Berg Guest

Similar Threads

  1. RecordCount Issues
    By supportcenter in forum Coldfusion Database Access
    Replies: 6
    Last Post: November 9th, 01:05 PM
  2. Indirect recordcount
    By a440guy in forum Macromedia ColdFusion
    Replies: 4
    Last Post: May 13th, 01:42 PM
  3. recordcount -1
    By middletree in forum ASP
    Replies: 8
    Last Post: October 16th, 02:06 PM
  4. RecordCount Property and SQL
    By Scott in forum ASP Database
    Replies: 2
    Last Post: July 22nd, 01:17 PM
  5. Why does the RecordCount property always = -1
    By George Mizzell in forum Macromedia Dreamweaver
    Replies: 2
    Last Post: July 13th, 01:27 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139