How do I work with displayed code?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
besbajah
Forum Newbie
Posts: 23
Joined: Fri May 20, 2005 1:00 pm
Location: Brazil

How do I work with displayed code?

Post by besbajah »

Hi,

Perhaps the most obvious of obvious of questions?

Is it possible to add a hyperlink to data that's been called from MySQL using PHP and then displayed on screen?
I'm confused and don't know how to add attributes to data that's called from a MySQL database. The data just sits there on screen and, well, how do you modify an individual piece of information?

I've moved my data from their old, stagnant html files into a MySQL database, but I've got a bit stuck.

Thanks,
Bes.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Your question is way to vaige for me to give you a good answer.
Perhaps show what you've got and what you want in the end.
QdollarSign
Forum Newbie
Posts: 5
Joined: Fri May 20, 2005 1:30 pm

php and html

Post by QdollarSign »

one way is to use html and php combined.

Code: Select all

<html>
<body><a href=&quote;

Code: Select all

<?php echo "$yourvarlink"; ?>

Code: Select all

&quote;&gt;your link name&lt;/a&gt;&lt;/body&gt;
&lt;/html&gt;
you could add php again in the link name to make that dynamic, and you could do the same thing for your link title.

hope this helps!
Q$
besbajah
Forum Newbie
Posts: 23
Joined: Fri May 20, 2005 1:00 pm
Location: Brazil

Post by besbajah »

In response to Jcart

I've got this snippet for you: -

<?
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
printf("%s", $row["Album"]);
echo "<br>";
}
?>

It works fine, it calls everything from the "Album" field and displays all the contents on screen. Yes, just what I want

HOWEVER, I used to have hyperlinks on all of the album names. When you click on an album name you get to see information about the album. Now all I get is the name of all the albums on the page. I don't know how to assign HTML hyperlink code to an outputted result, to a number of outputted results I mean. If I simply had just one output from the "Album" field I could encapsulate the whole lot in an <A> tag, mixing the PHP code before the </A>, but the output is 250+ albums, and the position in the display order changes all the time depending on other factors. Get my drift.

Simply just displaying the contents of my MySQL database isn't what I want, any ideas?

Bes.
besbajah
Forum Newbie
Posts: 23
Joined: Fri May 20, 2005 1:00 pm
Location: Brazil

Post by besbajah »

In response to Qdollarsign

Yes, I get your drift, thanks. (I just read your post after replying to Jcart).

You can embed the PHP in an <A>tag</A>

...but like I said, what happens when the PHP output is multiple records. That hyperlink will be the same for ALL the records, all 250+ of them!

Surely I don't have to write 250+ embeded PHP scripts, do I?
Obviously, every hyperlink is different, so, I will have to won't I?

Is there an easier way?

Bes.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

well you've just lost me. a hyperlink is no different from any other php output.

Code: Select all

while ($row = mysql_fetch_assoc($result)) {
  print("<a href='?page={$row['Album']}'>{$row['Album']}</a><br />");
}
O.o
besbajah
Forum Newbie
Posts: 23
Joined: Fri May 20, 2005 1:00 pm
Location: Brazil

Post by besbajah »

That's pretty cool Skara mate,

What I need to do then is create a field in MySQL called let's say
'Hyperlink'
and then reference the hyperlink with the relevant path a little something like this: -

print("<a href='?/path name={$row['Hyperlink']}'>{$row['Album']}</a>");

If that's the case then I've GOT IT !!!

Cheers,
Bes.
Post Reply