Jump to content

Help with Hyperlink


php_nooby82

Recommended Posts

Hi,

 

What I am trying to do may be simple, I just can't get it to work. Ok...

 

I am using Zend and so the database connect that I need for this is a simple call to it like

data->profile_name('username').

 

Ok, now to my question...I am trying to add a hyperlink to the login area of my website so that it will show the logged in user's personal profile page. Example:

 

www.randomsite.com/liarea/username

 

Where it says username I am trying add code there to show the username of the user that is logged in. I have tried lots of things and nothing works. Here is the latest thing I have tried:

 

<a href='/liarea/<?php echo $dmp->profile_data('username'); ?>'>www.randomsite.com</a>

 

The randomsite is fictitious so sorry if it leads to something weird.  ;)

 

Thanks for any help!

Link to comment
Share on other sites

Well, what I am trying to say is that it doesn't matter what it is. It could be any model and anything from the database. I just need to know how to add something from the database at the end of a hyperlink. I have seen it done with hyperlinks that do not use "/" like php?id= etc...but in my case I just want to know the code on how to add a field from the database to the end of a hyperlink.

 

Is that more clear? If not then dmp is Default_Model_People and profile data is a function in that model that gets the id of the user from the People's table in the database. I've used the code I gave to retrieve information on the user for other things so I know it works fine, but like I said above, my problem is trying to get it to work in a hyperlink. I thought all I would need to do was concatenate the two, but since I have it in those semi-quotes it is just being read instead of the action being taken.

 

Thanks again!

Link to comment
Share on other sites

If profile_data() returns a number the code you have provided would end up outputting (as an example)....

 

<a href='/liarea/13'>www.randomsite.com</a>

 

If its not, then your profile_data() method does not return what you think it does.

 

If not then dmp is Default_Model_People and profile data is a function in that model that gets the id of the user from the People's table in the database.

 

That doesn't help at all. There are many different ways to implement your models within Zend Framework because there isn't really much of a standard in this department. I for one use Doctrine.

Link to comment
Share on other sites

If profile_data() returns a number the code you have provided would end up outputting (as an example)....

 

<a href='/liarea/13'>www.randomsite.com</a>

 

Yes! That is what it does, well accept it being a number it is a username. The thing is, however, I have

'/liarea/'

already there and I need code to add the 13.

 

Something like:

 

$result = dmp->profile_data('username')
<a href='/liarea/.$result['username'].'>www.randomesite.com/liarea/.$result['username']</a>

 

Is this possible or would the enitre link need to be in the database for this to work?

 

Thanks so much!

Link to comment
Share on other sites

I did it! For those who ever run into this problem, first I closed the php to soon. It should be after the url and the url should be echoed. Next, all the parts that were not code needed to be in quotation marks. I also removed the php part from the <p> (don't know if that was apart of the problem) and it worked!  :D Thanks for all your help Thorpe!

 

Here is finally code:

 

<?php
$dmp = new Default_Model_People();
?>
<p> Some stuff</p>
<?php 
$authNamespace = new Zend_Session_Namespace('Zend_Auth');
$result = $dmp->profile_data($authNamespace->uid);

echo "<a href=/liarea/".$result["username"].">www.randomsite.com/profile/".$result["username"]."</a>"; ?>

 

Keep in mind this is Zend so for those who is trying to do this in a different framework or just with php and mysql alone remember to use Session or whatever Session that works with your framework.

 

Thanks again and tata for now!

Link to comment
Share on other sites

Keep in mind this is Zend so for those who is trying to do this in a different framework or just with php and mysql alone remember to use Session or whatever Session that works with your framework.

 

As I said, there was nothing in your code that is Zend specific. Its nice how now that you have resolved your problem you finally decide to post the relevant code. Would have been allot more helpful in your initial post though.

Link to comment
Share on other sites

Well, as I said before, I am very new to Zend so I am not sure but isn't this part of the code Zend specific?

 

$authNamespace = new Zend_Session_Namespace('Zend_Auth');

 

Thanks again for all your help.

 

Yeah, that is, but it was never posted with your original question.

Link to comment
Share on other sites

Oh right, because I didn't realize I needed it. I had exactly what I showed and said I was using Zend. Told you it was a Zend model I was using.

 

I am sorry, I assume to many things. I didn't mean to think you were a mind reader and just assumed you knew what I was talking about. I should have been a little more specific, but there was no Zend code before until I realized it was needed so I did not leave this out before. I showed you exactly what I had, which was obviously wrong.  ;)

 

By the way, the code I showed you last (before the solution) was correct, it just was missing the php stuff.

 

Thanks.

Link to comment
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.