Jump to content

Recommended Posts

can someone explain to me why this doesn't retrieve any names

all it prints out are <br />'s

<?php
$friends = mysql_query("SELECT * FROM friends WHERE friends_with = '{$_SESSION['id']}' AND friend = '{$_SESSION['id']}' AND accepted = 'yes'") or die(mysql_error());
$sql1 = mysql_fetch_array($friends);
while ($sql1 = $sql2) {
$friend = mysql_query("SELECT * FROM users WHERE id = '{$sql2['friends_with']}'") or die(mysql_error());
$friend_stuff = mysql_fetch_array($friend);
echo $friend_stuff['username'] ."<br />";
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/86798-not-retrieving-info/
Share on other sites

can someone explain to me why this doesn't retrieve any names

all it prints out are new lines

 

I'm amazed it does anything other than print error messages.

 

http://www.tizag.com/mysqlTutorial/mysqlfetcharray.php will point you in the right direction

Link to comment
https://forums.phpfreaks.com/topic/86798-not-retrieving-info/#findComment-443656
Share on other sites

ok i fixed that

put still no information is being printed its just <pre><br /></pre>'s

heres the whole entire page of code....

<?php
include("file_type.php");
if ($_SESSION['username'] == '') {
header("location:http://www.socialgrabbr.com/login.php");
}

$friends = mysql_query("SELECT * FROM friends WHERE friends_with = '{$_SESSION['id']}' AND friend = '{$_SESSION['id']}' AND accepted = 'yes'") or die(mysql_error());
while ($sql1 = mysql_fetch_array($friends)) {
$friend = mysql_query("SELECT * FROM users WHERE id = '{$sql1['friends_with']}'") or die(mysql_error());
$friend_stuff = mysql_fetch_array($friend);
echo $friend_stuff['username'] ."<br />";
echo $sql1['id'];
}

if (isset($_GET['type']) && $_GET['type'] == 'request') {
if (isset($_GET['request_id'])) {
$sql = mysql_query("SELECT * FROM users WHERE id = '{$_GET['request_id']}'") or die(mysql_error());
$req_user = mysql_fetch_array($sql);
if (!$req_user['username'] == '') {
$check = mysql_query("SELECT * FROM `friends` WHERE `friend` = '{$req_user['id']}' AND `friends_with` = '{$_SESSION['id']}' ") or die(mysql_error());
$c = mysql_num_rows($check);
if (!$c > 0) {
$submit = $_POST['submit'];
if ($submit) {
$query = mysql_query("INSERT INTO `friends` (`friend`, `friends_with`) VALUES ('{$req_user['id']}', '{$_SESSION['id']}')") or die(mysql_error());
echo "You have successfully added {$req_user['username']} as a friend.";
header("Refresh:2; url=http://www.socialgrabbr.com/profile.php?profile_id={$req_user['id']}");
} else {
?>
<form method='post' action='http://www.socialgrabbr.com/friends.php?type=request&request_id=<?=$_GET['request_id']?>'>
Are you sure you want add <?=$req_user['username']?> as a friend?<br><br>
<input type="submit" name="submit" value="Add Friend">  <input type="button" onclick="location.href='http://www.socialgrabbr.com/profile.php?profile_id=<?=$req_user['id']?>'" name="cancel" value="Cancel">
</form>
<?
}
} else {
echo "You have already added this person as a friend...<br><a href='". $_SERVER['HTTP_REFERER'] ."'>Go Back A Page</a>";
}
} else {
echo "Invalid Friend ID..";
}
}
}
include("footer.php");
?>

anyone now?

Link to comment
https://forums.phpfreaks.com/topic/86798-not-retrieving-info/#findComment-443664
Share on other sites

Hi,

 

$friend = mysql_query("SELECT * FROM users WHERE id = '{$sql1['friends_with']}'") or die(mysql_error());

$friend_stuff = mysql_fetch_array($friend);

 

From above query you are going yo receive multiple records or unique set of data. Well it doesn't matter but if you are fetching particular id then use mysql_fetch_row($friend);

 

Regards.

Link to comment
https://forums.phpfreaks.com/topic/86798-not-retrieving-info/#findComment-444790
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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