SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql column count

    Hi

    I am trying to restrict "name" to two entries in the table.

    This is the code

    $check = "SELECT $table.name, COUNT(*) FROM $table WHERE name = '".$_POST['name']."' GROUP BY name";
    $qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
    $total = count($qry);
    if ($total > 2) {
    $error_msg = "There are already 2 entries for $name in ";
    }

    I don't seem to be picking up the total for name can anyone help please.

  2. #2
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this;

    PHP Code:
    $check "SELECT $table.name, COUNT(*) FROM $table WHERE name = '".$_POST['name']."' GROUP BY name";
    $qry mysql_query($check) or die ("Could not match data because ".mysql_error());
    $total mysql_result($qry0);
    if (
    $total 2) {
    $error_msg "There are already 2 entries for $name in ";


    If that doesn't work, try removing $table.name,

    $name, from what I can see has no value. So you may have to try

    PHP Code:
    $check "SELECT COUNT(*) FROM $table WHERE name = '".$_POST['name']."' GROUP BY name";
    $qry mysql_query($check) or die ("Could not match data because ".mysql_error());
    $total mysql_result($qry0);
    if (
    $total 2) {
    $error_msg 'There are already 2 entries for ' $_POST['name'] . ' in ';



    Klik

  3. #3
    SitePoint Member
    Join Date
    Aug 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Klik second example works fine.


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
  •