mysql duplicate results

Thread Solved

Join Date: Sep 2009
Posts: 19
Reputation: armyguydave69 is an unknown quantity at this point 
Solved Threads: 0
armyguydave69 armyguydave69 is offline Offline
Newbie Poster

mysql duplicate results

 
0
  #1
Sep 26th, 2009
Okay, I'm a little confused - this code works perfectly fine in mysql; however, in php it keeps repeating the first person for about 15 rows. Can someone point me to what I'm missing here.

  1. $queryUsers = "SELECT user_id, zipcode, gender, housing_status, active, username FROM users WHERE user_id != '" . $_SESSION['user_id'] . "'
  2. AND active = 1";
  3. $dataUsers = mysqli_query($dbc, $queryUsers);
  4. $rowUsers = mysqli_fetch_array($dataUsers);

  1. echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
  2. while ($row = mysqli_fetch_array($dataUsers)) {
  3.  
  4. echo '
  5. <tr><td class="subtitle" height="30px" colspan="3" align="left" valign="middle">' . $rowUsers['username'] . '</td></tr>
  6. <tr><td width="21%" rowspan="8" align="center" valign="middle"><img alt="profile picture" name="profilepic" width="100" height="100" id="profile picture" /></td></tr>
  7. <tr class="oddrow"><td width="21%" align="left" valign="middle">Age:</td><td width="58%">' . $rowUsers['user_id'] . '</td></tr>
  8. <tr class="evenrow"><td align="left" valign="middle">Gender:</td><td>' . $rowUsers['gender'] . '</td></tr>
  9. <tr><td align="left" valign="middle">Location:</td><td>&nbsp;</td></tr>
  10. <tr class="evenrow"><td align="left" valign="middle">Looking for:</td><td>' . $rowUsers['housing_status'] . '</td></tr>
  11. <tr><td align="left" valign="middle">Has children:</td><td>&nbsp;</td></tr>
  12. <tr class="evenrow"><td align="left" valign="middle">Type of pets:</td><td>&nbsp;</td></tr>
  13. <tr class="oddrow"><td align="left" valign="middle">Inside Smoker:</td><td>&nbsp;</td></tr>
  14. <tr class="subtitle"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
  15.  
  16. }
  17. echo '</table>';

also if i change mysqli_fetch_array to mysqli_num_rows, I get a million empty rows.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 19
Reputation: armyguydave69 is an unknown quantity at this point 
Solved Threads: 0
armyguydave69 armyguydave69 is offline Offline
Newbie Poster

Re: mysql duplicate results

 
0
  #2
Sep 26th, 2009
I guess it helps if I have the variables named the same ($row = $rowUsers)...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 17
Reputation: flashyflashy is an unknown quantity at this point 
Solved Threads: 2
flashyflashy flashyflashy is offline Offline
Newbie Poster

Re: mysql duplicate results

 
0
  #3
Sep 26th, 2009
$_SESSION['user_id'] , I guess this is causing problem.
Try
  1. $session_user=$_SESSION['user_id'];
  2. $queryUsers = "SELECT user_id, zipcode, gender, housing_status, active, username FROM users WHERE user_id != '" . $session_user. "' AND active = 1";
Last edited by peter_budo; Sep 27th, 2009 at 8:18 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 343 | Replies: 2
Thread Tools Search this Thread



Tag cloud for MySQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC