SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all (again ),
    Can anybody tell me if there is a quick way to tell if any FIELDS in a selected row are empty without assigning every field to a variable?

    My select looks like this:-

    $query = "SELECT * from table where SID = '$idchecker'";

    If ANY fields in the selected row are empty, I need to throw an error out, otherwise proceed as normal.

    It would be handy if I could tell which field was empty too.

    Not important really, if it can't be done I'll just stick everything into variables and if..else it.

    Thanks!

  2. #2
    SitePoint Member
    Join Date
    Dec 2000
    Location
    The Netherlands
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $result = mysql_query($query);
    $result = mysql_fetch_array($result);
    $n = list ($result);
    $i = 0;
    while ($i<$n)
    {
    if (empty($result[$i])) { $error = true; }
    }
    if ($error) { print "AAAARGH!!!"; }
    Grtz,

    Leon Mergen

  3. #3
    SitePoint Member
    Join Date
    Dec 2000
    Location
    The Netherlands
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oops, I forgot the $i++ after the if() statement
    Grtz,

    Leon Mergen

  4. #4
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Solatis, I tried that code (with the $i++ ) and got the following error:-

    Parse error: parse error, expecting `'='' in testcode.php on line 15

    That line is :-

    $n = list($result);

    I checked the manual at php.net and can't work out the syntax. Bah!

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ken I am not sure if you got this one settled but here is how I accomplished it.

    PHP Code:
    <?
    $db 
    mysql_connect("localhost""root""") or DIE(mysql_error());
    mysql_select_db("dbname");

    $f mysql_list_fields("dbname""tablename");
    $columns mysql_num_fields($f);

    for (
    $i 0$i $columns$i++) {
        
    $fields[] = mysql_field_name($f$i);
        }
          


    $result mysql_query("SELECT * from tablename WHERE SID = '$SID'");
    $row mysql_fetch_array($result);
    foreach(
    $fields as $key => $val) {
        if (
    $row[$val] == "") {
            print 
    "$val was an empty field for this row<br>";;
            }
        else {
            print 
    "$val = ".$row[$val]."<br>";
            }    
        }
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •