#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Mumbai, India
    Posts
    276
    Rep Power
    15
    I have 4 columns and 100 rows data stored in mysql table. I want to read the first row second column, do some calculation, move to secord rwo second column and then third row second column.
    How to get the "CELL" Contents?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Seaside, CA
    Posts
    84
    Rep Power
    15
    Well, first you retrieve the second column from your database table. If you're not sure how to do this, there's a very simple explanation at thickbook.com.

    Then you manipulate the data. Here's the PHP manual page that gives you the mathematical operators:
    http://www.php.net/manual/html/language.operators.html

    ------------------
    From the day we're born, we're running out of time.
  4. #3
  5. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Fetching record from mysql database is very easy.

    if you want to get a particluar row in mysql then you can use mysql_data_seek() function before getting the value.you can specifiy the row number in the mysql_data_seek() function..

    eg:

    <?php

    $con=mysql_connect('localhost','username','password');
    //connection string.
    mysql_select_db('databasename',$con);
    //select database

    $query="select * from tblname where someconditions";
    //your sql query..

    $result=mysql_query($query,$con);
    //issue a query..

    mysql_data_seek($result,1)
    //fetch first row..
    //you can change the second argument for next row.(ie, 2,3..).
    //use a loop for that

    $row=mysql_fetch_array($result);

    echo $row["column2"];
    //print second column first row..
    ?>


    if you want to populate all values from second column then try the following..

    <?php

    $con=mysql_connect('localhost','username','password');
    //connection string.
    mysql_select_db('databasename',$con);
    //select database

    $query="select * from tblname where someconditions";
    //your sql query..

    $result=mysql_query($query,$con);
    //issue a query..

    if ($row = mysql_fetch_array($result)) {

    do {

    print $row["secondcolumn"];
    //print all the values of second column..


    } while($row = mysql_fetch_array($result));

    } else {print "no records!!";}

    ?>

    just try this exmples and see how it works..


    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited July 10, 2000).]
  6. #4
  7. No Profile Picture
    a total freak
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    33
    Rep Power
    15
    there's another example (and i think is much easier..) using the mysql_result command.. :

    $query_table = mysql_query("select tablename where somecondition");
    for($x=0;$x<mysq_num_rows($query_table);$x++)
    $data_to_calculate[$x] = mysql_result($query_table,$x,1);

    // the calculation goes below....

    ...


    the $query_table in mysql_result is the query the cell you wanted is taken from, $x is the row of tables (in your case, $x is from 0 till 100), and 1 means the number of columns counted from 0 (which also means that this is the second column)
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Mumbai, India
    Posts
    276
    Rep Power
    15
    I am getting an error message on line 11
    The line no. 11 is
    $domain_to_check[$x] = mysql_result($query_table,$x,1);

    The lines before that are
    $query_table = mysql_query("select domain from domain_watch");
    for($x=0;$x<mysql_num_rows($query_table);$x++);

    Warning: Unable to jump to row 1 on MySQL result index 2 in on line 11

    Please let me what's going wrong.
    Thanks a lot for all your support
  10. #6
  11. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    $domain_to_check[$x] = mysql_result($query_table,$x,1);

    use offset 0 for third argument..You are fetching only one field values so your offset start from 0.or you can use field name directly..

    try this:

    $domain_to_check[$x] = mysql_result($query_table,$x,0);


    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."
  12. #7
  13. No Profile Picture
    a total freak
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    33
    Rep Power
    15
    yes.. just like what Shiju Rajan said.. you see, your only getting one column by the command:

    mysql_query("select domain from domain_watch");

    if you are getting any column from the mysql_query the third argument of mysql_result will do just fine with '1',.. but like what i said and what Shiju said, the third argument of mysql_result is the array of rows from the query, and it starts from 0

    ------------------
    ---freakyG!---
    kinumedia, web developer

Similar Threads

  1. C program to read from a data file into an array
    By rathornton in forum C Programming
    Replies: 4
    Last Post: March 16th, 2004, 11:23 AM
  2. Replies: 3
    Last Post: February 11th, 2004, 08:30 AM
  3. mysql data lost
    By imola in forum MySQL Help
    Replies: 1
    Last Post: February 10th, 2004, 07:39 AM
  4. Replies: 1
    Last Post: February 5th, 2004, 06:17 AM
  5. question about read data
    By jinwanguiuc in forum C Programming
    Replies: 2
    Last Post: February 3rd, 2004, 11:17 PM

IMN logo majestic logo threadwatch logo seochat tools logo