0

So I have looked around the internet, and couldn't find anything that could be related to my issue.

This is part of my DB:

ID  |     English    |    Pun    |  SID   |  Writer   |
=======================================================
1   |      stuff     |   stuff   |   1    |   Full    |
2   |      stuff     |   stuff   |   1    |   Rec.    |
3   |      stuff     |   stuff   |   2    |   Full    |
4   |      stuff     |   stuff   |   2    |   Rec.    |

Now how would I get all rows with SID being equal to 1.

Like this

ID  |     English    |    Pun    |  SID   |  Writer   |
=======================================================
1   |      stuff     |   stuff   |   1    |   Full    |
2   |      stuff     |   stuff   |   1    |   Rec.    |

Or when I want to get all rows with SID being equal to 2.

ID  |     English    |    Pun    |  SID   |  Writer   |
=======================================================
3   |      stuff     |   stuff   |   2    |   Full    |
4   |      stuff     |   stuff   |   2    |   Rec.    |

This is my current SQL Query using SQLite:

SELECT * FROM table_name WHERE SID = 1

And I only get the first row, how would I be able to get all of the rows?

Here is my PHP Code:

class GurDB extends SQLite3
{
    function __construct()
    {
        $this->open('gurbani.db3');
    }
}

$db = new GurDB();
$mode = $_GET["mode"];

if($mode == "2") {
    $shabadnum = $_GET["shabadNo"];
    $result = $db->query("SELECT * FROM table_name WHERE SID = $shabadnum");
    $array = $result->fetchArray(SQLITE3_ASSOC);
    print_r($array);
}
11
  • Aren't you getting invalid column 1 error Commented Mar 29, 2016 at 15:22
  • SELECT * FROM table where sid = 1 . Commented Mar 29, 2016 at 15:22
  • You don't need the quotes around the column name ('SID'). And you only need them around the value (1) if it's a VarChar; but it looks like it could be an int. If so: get rid of all those quotes (including the table name, if you're enclosing that in quotes). Commented Mar 29, 2016 at 15:23
  • @B.ClayShannon That's a back tick and it is for reserved words, a string should be wrapped with a singel quote mark ' Commented Mar 29, 2016 at 15:24
  • You shouldn't have your table name in any sort of symbol like that. See sagi's comment. Your table name is not a reserved word, or shouldn't be; that would be asking for trouble, or at least confusion. Commented Mar 29, 2016 at 15:25

1 Answer 1

1

Fetch array only gives you one row... you want something like this:

while($row = $result->fetch_array())
{
  $rows[] = $row;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.