SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast falfool's Avatar
    Join Date
    Jun 2003
    Location
    Amman
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help! little mysql query, somebody help me in this

    Hello all,
    Im new to PHP programming, and im having a little problem in my script:

    I want to assign the columns' names to a variables

    $sql = "SHOW COLUMNS FROM $table_name";
    $sql_result = mysql_query($sql) or die...

    while ($cols = mysql_fetch_row($sql_result) ) {
    for ($i = 0; $i < count($cols); ++$i) {
    if ($cols[$i] == "" || $cols[$i] == 0) {
    unset($cols[$i]);
    }
    echo "<P>$cols[$i]";
    $column[$i] = $cols[$i];
    }
    }

    The problem in this code that it gives me all the columns' names and types and NULL values etc. i want it just to give me the column NAME
    i will appreciate any help, sorry for long message
    Thank You, FalfoOL[QUOTE]

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Bay Area, California
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    PHP Code:
    while(list($name) = mysql_fetch_row($sql_result)) {
        
    $column[$i] = $name;
        echo 
    "<p>$name";
        
    $i++;

    Each time it gets to a new column, it puts the name of the column into $name and ignores the rest of it. It then places each column name into the $column[] array. Let me know if that's not what you meant

  3. #3
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    I've used this code to do the same thing before.
    PHP Code:
    while ( $row mysql_fetch_array($rs) ) {
        foreach ( 
    $row as $field ) {
            
    $dbField[] = $field;
            break;
        }


  4. #4
    SitePoint Enthusiast falfool's Avatar
    Join Date
    Jun 2003
    Location
    Amman
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks alot guyes.. but there is another problem actually... im gonna try to fix it, if i couldnt ill let u in thank you


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
  •