Jump to content

in_array within query


doddsey_65

Recommended Posts

i did that but it only echoes one username:

 

$user_query = mysqli_query($link, "SELECT 
						user_username, user_avatar,
						user_regdate
						FROM ".TBL_PREFIX."members
						") or die(mysqli_error($link));
while($user_info = mysqli_fetch_array($user_query, MYSQLI_ASSOC))
{
if (in_array($user_info['user_username'], $likes))
{
	$user_name .= profile_link("", $user_info['user_username'], "");
	$user_avatar .= "<img src=\"./avatars/{$user_info['user_avatar']}\" alt=\"avatar\" />";
	$user_reg_date .= asf_date($user_info['user_regdate'], 1);
}							
}

Link to comment
Share on other sites

$likes = explode(", ", $p_name_info['post_likes']);

 

post_likes is a db table with content like

 

user1, user2, user3

 

there is no case sensitive issue but to be safe i added strtolower on the array and database field but still only shows one result

Link to comment
Share on other sites

you could create an array for each of those results in the if statement and the use foreach to spit them out where needed

above the while statement have

$user_name=array();
$user_avatar=array();
$user_reg_date=array();

then in the if statement

$user_name[]= profile_link("", $user_info['user_username'], "");
$user_avatar[]= "<img src=\"./avatars/{$user_info['user_avatar']}\" alt=\"avatar\" />";
$user_reg_date[]= asf_date($user_info['user_regdate'], 1);

Link to comment
Share on other sites

<table>
<?php 
$num=(count($user_name)-1);
for ($i=0;$i<=$num;$i++) {
  echo "<tr>\n";
  echo "<td>$user_avatar[$i]</td>";
  echo "<td><p><?php echo $user_name[$i]</p><p>$user_reg_date[$i]</p></td>\n";
  echo "</tr>\n";
}
?>
</table>

 

something like that should work

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.