Jump to content

Php/sql Script Will Not Display First Result


ryanfilard
 Share

Recommended Posts

EDIT: Two things:

 

1. You're using a single-quoted string to output the value. That won't work as only double-quoted strings extrapolate values.

2. You can't output an array value in a string unless you either concatenate or surround it in braces.

 

In short you want either:

 

echo $row_userfriends['user'];

 

or:

 

echo "{$row_userfriends['user']}";

 

If that doesn't solve it, show your query and table structure.

Edited by KevinM1
Link to comment
Share on other sites

User is text, friend is text, and accepted is one

 

JlyQy.png

This is what I am using to display the data

mysql_select_db($database_main, $main);
$query_userfriends = "SELECT * FROM friends WHERE `friend` = '$uid' LIMIT 9";
$userfriends = mysql_query($query_userfriends, $main) or die(mysql_error());
$row_userfriends = mysql_fetch_assoc($userfriends);

Link to comment
Share on other sites

I made this script:

 <?PHP
       while($row_userfriends = mysql_fetch_array($userfriends))
 {
 echo '$row_userfriends['user']';
 }
 ?>

problem is it works but does not display the first result. Whats wrong? :-\

mysql_select_db($database_main, $main);
$query_userfriends = "SELECT * FROM friends WHERE `friend` = '$uid' LIMIT 9";
$userfriends = mysql_query($query_userfriends, $main) or die(mysql_error());
$row_userfriends = mysql_fetch_assoc($userfriends);

 

Instead of showing snippets, you should show all of the code that is pertinent. If your latest code comes before the code in your first post, then it is:

 

mysql_select_db($database_main, $main);
$query_userfriends = "SELECT * FROM friends WHERE `friend` = '$uid' LIMIT 9";
$userfriends = mysql_query($query_userfriends, $main) or die(mysql_error());
$row_userfriends = mysql_fetch_assoc($userfriends);
       while($row_userfriends = mysql_fetch_array($userfriends))
 {
 echo '$row_userfriends['user']';
 }

 

If you look at that, you are fetching the first row just before the while. Since you don't do anything with $row_userfriends before the while statement, you are effectively thowing away the first record. Remove the fetch statement (before the while) and you should be golden.

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

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