0

Here is my current code:

        $sql = "SELECT * FROM user_posts";
        $result = mysql_query($sql); 
        $row = mysql_fetch_array($result);
        while ($row = mysql_fetch_array($result)) 
        { 
        print $row['message'];
        } 

My goal is to show all of the data in that SQL database through an array. But currently, it only shows the latest one and nothing else. How am I able to do this? Thanks!

2 Answers 2

2

You should remove this line

$row = mysql_fetch_array($result);

Apart from that it should display every message

Sign up to request clarification or add additional context in comments.

2 Comments

Works great! So that means I should not specify the variable before to make it work?
What you're doing there is effectively removing the first row from the results. Each call to mysql_fetch_array moves on to the next row
0

You're only getting the one row because you overwrite the $row variable with the values from your results array.

$sql = "SELECT * FROM user_posts";
$result = mysql_query($sql); 
while ($info = mysql_fetch_array($result)){ 
    print $info['message'];
}

Change it to something like that.

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.