Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-09-2012, 05:34 PM   PM User | #1
COcode
New to the CF scene

 
Join Date: Dec 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
COcode is an unknown quantity at this point
Row Count with Dynamic URLs

The code below use to reference username. I changed it to go by first/last name. Except the system goes by username when opening dynamic URLs. I have the rows printing out first and last name and when you select the name it needs to open website by "user".

The url name appears to have first and last name (this is what I want), but when you select name I want it to go by username.

CODE:

PHP Code:
<? if (isset($_GET['add']))
{
    
$add sanitizeString($_GET['add']);
    
$query "SELECT * FROM friends WHERE user='$add'
              AND friend='$user'"
;
    if (!
mysql_num_rows(queryMysql($query)))
    {
        
$query "INSERT INTO friends VALUES ('$add', '$user')";
        
queryMysql($query);
    }
}
elseif (isset(
$_GET['remove']))
{
    
$remove sanitizeString($_GET['remove']);
    
$query "DELETE FROM friends WHERE user='$remove'
              AND friend='$user'"
;
    
queryMysql($query);
}
$result queryMysql("SELECT Concat(firstname,' ', lastname), user FROM profiledetails ORDER BY lastname");
$result2 queryMysql("SELECT user FROM members ORDER BY user");
$num2=mysql_num_rows($result2);
$num mysql_num_rows($result);
echo 
"<h5>Follow your friends progress and find people with similar interests by clicking below</h5><ul>";
for (
$j $j $num ; ++$j)
{
    
$row mysql_fetch_row($result);
    
$row2=mysql_fetch_row($result2);
    if (
$row[0] == $user) continue;
    echo 
"<li><a href='members.php?view=$row[0]'>$row[0]</a>";
    
$query "SELECT * FROM friends WHERE user='$row[0]'
              AND friend='$user'"
;
    
$t1 mysql_num_rows(queryMysql($query));
    
$query "SELECT * FROM friends WHERE user='$user'
              AND friend='$row[0]'"
;
    
$t2 mysql_num_rows(queryMysql($query));
    
$follow "follow";
    if ((
$t1 $t2) > 1)
    {
        echo 
" &harr; is a mutual friend";
    }
    elseif (
$t1)
    {
        echo 
" &larr; following";
    }
    elseif (
$t2)
    {
        
$follow "recip";
        echo 
" &rarr; is following you";
    }
    if (!
$t1)
    {
        echo 
" [<a href='members.php?add=".$row[0] . "'>$follow</a>]";
    }
    else
    {
        echo 
" [<a href='members.php?remove=".$row[0] . "'>drop</a>]";
    }
}
?>

I need the print rows of
PHP Code:
<li>a href=members.php?view=$row[0]>$row[0]</a>"; 
The URL needs to open referencing user, but the row needs to print first/last name.

Any help would be appreciated.
COcode is offline   Reply With Quote
Old 12-09-2012, 05:53 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
I don't quite follow your description but..

PHP Code:
$result queryMysql("SELECT Concat(firstname,' ', lastname), user FROM profiledetails ORDER BY lastname"); 
concatenates (joins) firstname and lastname separated by a space, which becomes the first field returned, which you refer to later as $row[0].
PHP Code:
$result queryMysql("SELECT firstname, lastname, user FROM profiledetails ORDER BY lastname"); 
will keep firstname and lastname separate, referred to as $row[0] and $row[1] in your later code. Then, to perform your comparison, you would use:
PHP Code:
if ($row[0] . ' ' $row[1] == $user) continue; 
which temporarily rejoins first and lastname.

I may not have answered your precise requirement, but I'm sure the answer is in the above description
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 12-09-2012, 06:47 PM   PM User | #3
COcode
New to the CF scene

 
Join Date: Dec 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
COcode is an unknown quantity at this point
Basically, I have first/last name printing for the rows. The user will see first/last name but when they select first and last name I need it to open URL with username instead of first/last name.

Example:
PHP Code:
echo "<li><a href='members.php?view=$row[user]'>$row[firstlastname]</a>"
firstname lastname when selected opens URL by username.

The HREF is where I am stuck because I need it to call username. but when row prints it must be first/last name...

Last edited by COcode; 12-09-2012 at 06:50 PM..
COcode is offline   Reply With Quote
Old 12-09-2012, 08:11 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Does $user contain the username?

PHP Code:
echo "<li><a href='members.php?view=$user'>" $row[0] . ' ' $row[1] . "</a>";
// or

echo "<li><a href='members.php?view=$user'>{$row[0]} {$row[1]}</a>"
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 12-09-2012, 11:10 PM   PM User | #5
COcode
New to the CF scene

 
Join Date: Dec 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
COcode is an unknown quantity at this point
No it does not, I have to pull user form my SQL in $row[0] basically row[0] print all the rows. so far row[0] print first and last name. i need row[0] to also print user name

Last edited by COcode; 12-09-2012 at 11:23 PM..
COcode is offline   Reply With Quote
Old 12-09-2012, 11:26 PM   PM User | #6
COcode
New to the CF scene

 
Join Date: Dec 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
COcode is an unknown quantity at this point
I fixed it!!! I just had to call $row[1] and it pulled user. $row[0] is my concat string with first and last name $row[1] is for user.


hehe i dont know how i misssed that one
COcode is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:14 AM.


Advertisement
Log in to turn off these ads.