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

    Join Date
    Jun 2000
    Location
    Canada
    Posts
    35
    Rep Power
    15
    I am having problems with a test script i am writing...

    I set up an html form composed of 3 checkboxes:

    <html>
    <body>
    <FORM action="test.php" method="post">
    <INPUT TYPE="checkbox" NAME=job_id[] value="1"> Job 1<br>
    <INPUT TYPE="checkbox" NAME=job_id[] value="5"> Job 5<br>
    <INPUT TYPE="checkbox" NAME=job_id[] value="10">Job 10<br>
    <INPUT TYPE=submit NAME=submit value="Get these jobs"<br>
    </FORM>
    </body>
    </html>

    Then I have a php script in order to get the datas from a SQL database. I want only the datas corresponding to the selected checkboxes. I wrote a FOR loop, but I get an error message: SQL cannot jump to row 1

    test.php:
    <?php

    $hostname="myhost";
    $username="me";
    $password="mypasswd";
    $dbname="db";
    $usertable="table";

    /* Make connection to database*/
    MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");

    @mysql_select_db($dbname) or die("Unable to select database");

    if (!isset($job_id))
    {$job_id= 0;
    print "<center>Error: no job selected!</center>";}

    else
    {$number=count($job_id);

    FOR ($i=0; $i< $number; $i++ )
    {$job=$job_id[$i];
    $query="SELECT * FROM $usertable_jobs WHERE (job_id='$job')";
    $result=MYSQL_QUERY($query);
    $id=mysql_result($result, $i, "job_id");
    PRINT"<center>You have selected the job number: $id</center>";}

    }

    ?>

    Does anyone know what i am missing?
    Thanks a lot!
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    FOR ($i=0; $i< $number; $i++ )
    {$job=$job_id[$i];
    $query="SELECT * FROM $usertable_jobs WHERE (job_id='$job')";
    $result=MYSQL_QUERY($query);
    $id=mysql_result($result, $i, "job_id");
    PRINT"<center>You have selected the job number: $id</center>";}
    >>


    i think you are doing a small mistake here..

    [b]$id=mysql_result($result, $i, "job_id");[b]
    you are rotating the result loop based on array count(it may be maximum 3,your query may not fetch any record some times.still it will try to display a particular row).


    try this..

    FOR ($i=0; $i< $number; $i++ )
    {$job=$job_id[$i];
    $query="SELECT * FROM $usertable_jobs WHERE (job_id='$job')";
    $result=MYSQL_QUERY($query);
    if(mysql_num_rows($result)>0){
    //if your query return some result then..

    for($a=0;$a<mysql_num_rows($result);$a++){
    $id=mysql_result($result, $a, "job_id");
    PRINT"<center>You have selected the job number: $id</center>";
    }
    }
    }

    Good Luck!!




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

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Canada
    Posts
    35
    Rep Power
    15
    Thanks a LOT!!!!!
    it did the trick...

Similar Threads

  1. Replies: 13
    Last Post: June 4th, 2004, 05:49 PM
  2. Highlight search result from mysql database search
    By Gurt in forum PHP Development
    Replies: 3
    Last Post: February 17th, 2004, 04:39 AM
  3. Replies: 0
    Last Post: February 11th, 2004, 08:48 AM
  4. Database search highlighting problem - Stuck!
    By nro in forum PHP Development
    Replies: 5
    Last Post: January 30th, 2004, 09:44 PM
  5. Replies: 0
    Last Post: January 27th, 2004, 11:11 AM

IMN logo majestic logo threadwatch logo seochat tools logo