user3641971
user3641971

Reputation: 137

Getting error while using limit?

I am displaying a question along with their options. I want to use limit query.

But I am getting error. If I am using any other query in the $query string, I am not getting any error.

<?php 

$dbc = mysqli_connect('localhost','root','1234','myown')
or die('unable to connect');

// $query = "Select * from question";
// $result = mysqli_query($dbc,$query);
// $num_rows = mysqli_num_rows($result);

$range = rand(0,6); 
echo $range;
$query = "select * from question where limit 1,1";

$result = mysqli_query($dbc,$query)
or die("Error.\n");           
$row = mysqli_fetch_array($result);

?>

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <h3> <?php echo $row['sawal']; ?></h3>

        <form method = "POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
            <input type="radio"  name=" answer" value="A" ><?php echo $row['A']; ?><br>
            <input type="radio"  name=" answer" value="B" ><?php echo $row['B']; ?><br>
            <input type="radio"  name=" answer" value="C" ><?php echo $row['C']; ?><br>
            <input type="radio"  name=" answer" value="D" ><?php echo $row['D']; ?><br>

            <input type="submit" name="submit" value="ANSWER"/>
        </form>
    </body>
</html>
<?php
mysqli_close($dbc);
?>

How can I overcome it ?

Upvotes: 0

Views: 50

Answers (2)

Shiwam Prasad Gupta
Shiwam Prasad Gupta

Reputation: 13

You are starting ur LIMIT from 1 and ending to 1..so u r getting error.. try this

"your query" (dont use where statement here) LIMIT 0, 1;

Upvotes: 0

may saghira
may saghira

Reputation: 564

$query = "select * from question limit 1,1";

Upvotes: 3

Related Questions