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);
}							
}

$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

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);

<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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.