show all fields except id in php

Discussion in 'PHP' started by gilgalbiblewheel, Dec 6, 2009.

  1. #1
    $fields = array();
    $sql = "SHOW FIELDS FROM ".$acronym;
    $result = mysql_query($sql);
    $i = 1; // to skip the id field
    while ($row = mysql_fetch_array($result)) {
    	$fields[]= $row['Field'];
    }
    $str = implode(", ", $fields);
    echo $str;
    
    
    PHP:
    This is where it's going to fit:
    $sql = "INSERT INTO ".$acronym." (".$str.") VALUES (".$strLine[$line].")";

    I want to get all the td tags 9/record excluding the ID field inserted.
     
    gilgalbiblewheel, Dec 6, 2009 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    Add
    if($row['Field']=="id"){
    continue;
    }
    after
    while ($row = mysql_fetch_array($result)) {

    
    $fields = array();
    $sql = "SHOW FIELDS FROM ".$acronym;
    $result = mysql_query($sql);
    $i = 1; // to skip the id field
    while ($row = mysql_fetch_array($result)) {
        if($row['Field']=="id"){
            continue;
        }
        $fields[]= $row['Field'];
    }
    $str = implode(", ", $fields);
    echo $str;
    
    Code (markup):
     
    s_ruben, Dec 6, 2009 IP
  3. clinton

    clinton Well-Known Member

    Messages:
    2,166
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Good thinking, and I think you can just use SELECT as well and leave out id.
     
    clinton, Dec 7, 2009 IP
  4. metapix

    metapix Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Can this help:
    codediesel.com/mysql/selecting-all-except-some-columns-in-mysql/
     
    metapix, Dec 7, 2009 IP