CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Row Count with Dynamic URLs (http://www.codingforums.com/showthread.php?t=283853)

COcode 12-09-2012 05:34 PM

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.

AndrewGSW 12-09-2012 05:53 PM

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 :thumbsup:

COcode 12-09-2012 06:47 PM

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

AndrewGSW 12-09-2012 08:11 PM

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>"


COcode 12-09-2012 11:10 PM

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

COcode 12-09-2012 11:26 PM

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


All times are GMT +1. The time now is 08:41 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.