+ Reply to Thread
Results 1 to 4 of 4

Thread: Php MySql and Tables

  1. #1
    Mentor coltrane's Avatar
    Join Date
    May 2001
    Location
    North Carolina
    Posts
    1,390

    Php MySql and Tables

    I have written a script that accesses my MySql dB and outputs the data into html tables...what I want to do now is add the ability to edit and delete data in MySql tables INSIDE the html tables.......for some reason my logic is off and its not working

    Can someone put me in the right path?

  2. #2
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    809

    Re: Php MySql and Tables

    What are you looking for?? something like:
    Code:
     DELETE FROM table WHERE somthing = selected;
    
    or
    
    UPDATE table SET item = change_item WHERE something = selected;
    ::edit::
    Or is it the ALTER trigger you're looking for ?? if you want to change the table structure it self.

  3. #3
    Mentor coltrane's Avatar
    Join Date
    May 2001
    Location
    North Carolina
    Posts
    1,390

    Re: Php MySql and Tables

    Code:
    <?php
    
    if (!isset($query) || empty($query))
        {$query = "select * from sccp";}
    //stripslashes are needed because the select statement is
    //coming from a form.
    $query=stripslashes($query);
    
    mysql_connect("localhost", "dba", "purge26")
        or die("Could not connect to MySql Server");
    mysql_select_db("shift")
        or die("Could not open the Shift Database");
    $result = mysql_query($query) or
        die( mysql_error() );
    
    $number_cols = mysql_num_fields ($result);
    
    echo "<b>query: $query</b>";
    //layout table header
    echo "<table border = 1>\n";
    echo "<tr align=center>\n";
    
    for ($i=0; $i<$number_cols; $i++)
    {
        echo "<th>" . mysql_field_name($result, $i). "</th>\n";
    }
    echo "</tr>\n"; //end table header
    
    
    //layout table body
    while ($row = mysql_fetch_row($result))
    {
        echo "<tr align=left>\n";
        for ($i=0; $i<$number_cols; $i++)
        {
            echo "<td>";
            if (!isset($row[$i])) //test for null value
                {echo "NULL";}
            else
                {echo $row[$i];}
            echo "</td>\n";
        }
        echo "</tr>\n";
    }    
    
    echo "</table>";
    ?>
    And I want to able to perform INSERTS and UPDATES from within the html tables, but I cant figure it out the best way to do it....I need more caffeine, but until then, I need assistance/opinions.

  4. #4
    Mentor coltrane's Avatar
    Join Date
    May 2001
    Location
    North Carolina
    Posts
    1,390

    Re: Php MySql and Tables

    nevermind, i got it
    will post the code later

+ Reply to Thread

Similar Threads

  1. Tutorial: phpBB 2 forum on a home server for home users on Ubuntu
    By AljoshaNL in forum Linux - Software, Applications & Programming
    Replies: 5
    Last Post: 03-15-2006, 10:58 PM
  2. Simple mysql questions
    By elovkoff in forum Linux - Hardware, Networking & Security
    Replies: 3
    Last Post: 08-06-2003, 02:37 PM
  3. Hopefully quick q on MySQL
    By Schotty in forum Linux - Software, Applications & Programming
    Replies: 9
    Last Post: 02-25-2003, 01:16 PM
  4. MySQL user question
    By mcdougrs in forum Linux - Hardware, Networking & Security
    Replies: 3
    Last Post: 12-09-2002, 12:56 AM

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