0

I have the following table set in my mysql database

mem_id | pid | content
     0 |   1 | All the content is here
     0 |   2 | All the content is here
     0 |   3 | All the content is here

Now the problem is to get all matching mem_id values and store it in a array in php.

Example: A variable called $id has value 0

So now I have to get all values under the column content but only those which matches the mem_id of the user.

Could anyone help me with this, I need it in php and using mysql query to get all the values.

My current code:

$con=mysqli_connect("localhost","*****","******","*****");

// Check connection
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM user_friends WHERE mem_id = '$_SESSION[SESS_MEMBER_ID]' LIMIT 1");

while($row = mysqli_fetch_array($result)) 
{ 
    $friends = $row['fid'];
} 
0

2 Answers 2

1
SELECT * FROM yourTABLE WHERE mem_id=0   // or 1 or 2 or 3 etc

Using PHP you could query it like:

<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$id = intval($id);  // Put your ID here
$query = "SELECT * FROM yourTABLE WHERE mem_id=$id";
if ($result = mysqli_query($link, $query)) {
    while ($row = mysqli_fetch_assoc($result)) {
     print_r($row); 
    }
    mysqli_free_result($result);
}
?>
Sign up to request clarification or add additional context in comments.

Comments

0
$query="select * from TABLE_NAME where `mem_id`='$id'";

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.