Need Help With Implementing Simple Stuff with PHP and MYSQL -
here code -
<?php $u = $_session['username']; while($fetchy = mysqli_fetch_array($allusers)) { mysqli_select_db($connect,"button"); $select = "select * button sessionusername='$u' , response = 'approve'"; $query = mysqli_query($connect,$select) or die('oops, not connect'); $result= mysqli_fetch_array($query); $email = mysqli_real_escape_string($connect,trim($result['onuser'])); echo $email; if($email){ mysqli_select_db($connect,"users"); $select_name = "select name, icon profile email = '$email'"; $query_2 = mysqli_query($connect,$select_name) or die('oops, not connect. sorry.'); $results= mysqli_fetch_array($query_2); $name = mysqli_real_escape_string($connect,trim($results['name'])); $icon = mysqli_real_escape_string($connect,trim($results['icon'])); echo $name; }
}
now, there 2 reponses in db. so, 2 names getting echoed, both same. why so? eg
db - names - apple , orange.
displayed - apple apple.
database example -
sessionusername onuser s@s.com apple s@s.com orange
edited
using @endophage's method -
appleorange , appleorange.
try this, had while loop in wrong place:
<?php $u = $_session['username']; mysqli_select_db($connect,"button"); $select = "select * button sessionusername='$u' , response = 'approve'"; $query = mysqli_query($connect,$select) or die('oops, not connect'); while($result = mysqli_fetch_array($query)) { $email = mysqli_real_escape_string($connect,trim($result['onuser'])); echo $email; if($email){ mysqli_select_db($connect,"users"); $select_name = "select name, icon profile email = '$email'"; $query_2 = mysqli_query($connect,$select_name) or die('oops, not connect. sorry.'); $results= mysqli_fetch_array($query_2); $name = mysqli_real_escape_string($connect,trim($results['name'])); $icon = mysqli_real_escape_string($connect,trim($results['icon'])); echo $name; } }
Comments
Post a Comment