php - how to create a variable using an array? -
this code
$get_favory = mysql_query("select * favory user1='$username'"); $values = ""; while($fav = mysql_fetch_assoc($get_favory)) { $user2 = $fav['user2']; $values = " or added_by='".$user2."'"; } echo $values;
the values variable must : or added_by='zac' or added_by='john' or added_by='emily'
result : or added_by='zac'
what have do?
why code not working
you're overwriting variable every time instead of appending new value.
solution
replace
$values = " or added_by='".$user2."'";
with
$values .= " or added_by='".$user2."'";
don't use mysql_ extension
mysql_ extension deprecated. should use mysqli_ instead. code should be:
$connect = mysqli_connect(host,username,password,db_name); $get_favory = mysqli_query($connect,"select * favory user1='$username'"); $values = ""; while($fav = mysqli_fetch_assoc($get_favory)) { $user2 = $fav['user2']; $values .= " or added_by='".$user2."'"; } echo $values;
Comments
Post a Comment