Results 1 to 4 of 4

Thread: help required for php n mysql

  1. #1
    Join Date
    Mar 2007
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question help required for php n mysql

    I am very new in php and mysql and am stuck at a point in my project.i am explaining my problem:
    i have a table called job which has the following fields
    id
    jobcode
    subject
    description
    postdate
    lastdate
    opening
    url

    i want to import data from this table such the subject(which is the 2nd col of the row ,id wont be imported) is a link to another page which is the url. the rows in the table keep increasing as data is stored in the database.
    if u could help me out i will be really greatful.
    thanks in advance..suk

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Can you rephrase the things you've mentioned in your posting. I don't think I've understood it correctly. According to my understanding you want to retrieve data from a database table.

    If you can mentioned what exactly are you trying to achieve people can understand the problem and thus troubleshoot more easily.

  3. #3
    Join Date
    Mar 2007
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default re:

    wht i want is a page whr a table will be displayed with all the fields in the database mentioned..the values in the field subject shud be displayed as a link which whn clicked is directed to the value mentoned in "url" in the database table job.
    example:
    let the entries in table job of the database be:
    id jobcode subject description postdate lastdate opening url
    1 sw01 tester jbghv 20/04/07 25/04/07 3 tester.php

    the table tht shud be displayed in the front end shud be

    jobcode subject lastdate opening
    sw01 tester 25/04/07 3

    the tester shud be a link to the page tester.php will hv the job description.

    as more jobs are entered into the database the front end table shud keep increasing in size
    i hv attached the code i hv..its displayin the table but not the subject field..
    hope u hv understood the problem and can help me.
    thanks

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Try the following code

    PHP Code:
    <?php
    class database
    {
        private 
    $db_handle;
        private 
    $user_name;
        private 
    $password;
        private 
    $data_base;
        private 
    $host_name;
        private 
    $sql;
        private 
    $results;

        function 
    __construct($host="localhost",$user,$passwd)
        {
            
    $this->db_handle mysql_connect($host,$user,$passwd);
        }

        function 
    dbSelect($db)
        {
            
    $this->data_base $db;
            if(!
    mysql_select_db($this->data_base$this->db_handle))
            {
                
    error_log(mysql_error(), 3"/phplog.err");
                die(
    "Error connecting to Database");
            }
        }
        
        function 
    executeSql($sql_stmt)
        {
            
    $this->sql $sql_stmt;
            
    $this->result mysql_query($this->sql);
        }
        function 
    returnResults()
        {
            return 
    $this->result;
        }
    }

    $user "root";
    $passwd "";

    $db "newTest"
    $sql "SELECT * FROM JOB ORDER BY jobcode";

    $dbObject = new database($host,$user,$passwd);

    $dbObject->dbSelect($db);

    $dbObject->executeSql($sql);


    $res $dbObject->returnResults();

    echo 
    "<table cellspacing='0' cellpadding='0' width='960' border='1'>\n<tr>";
    echo 
    "<td width='100'>Job Code</td>";
    echo 
    "<td width='6600'>Subject</td>";
    echo 
    "<td width='100'>Last Date</td>";
    echo 
    "<td width='100'>Opening</td>";
    echo 
    "</tr><tr>";

    while(
    $record mysql_fetch_object($res))
    {
        echo 
    "<td width='100'>".$record->jobcode."</td>";
        echo 
    "<td width='660'><a href='".$record->url."'>".$record->subject."</a></td>";
        echo 
    "<td width='100'>".$record->lastdate."</td>";
        echo 
    "<td width='100'>".$record->opening."</td>";
        echo 
    "</tr><tr><td colspan='5'>&nbsp;</td></tr><tr>";
    }
    echo 
    "</tr></table>";
    ?>
    Code:
    $user = "root"; //change this line in the above code with your db user name
    $passwd = "";  //change this line in the above code with your db password
    
    $db = "newTest";  //change this line in the above code with your db name
    $sql = "SELECT * FROM JOB ORDER BY jobcode"; //change this query if your table name is not JOB

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
  •