Page 1 of 1
How do I work with displayed code?
Posted: Fri May 20, 2005 1:21 pm
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.
Posted: Fri May 20, 2005 1:39 pm
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.
php and html
Posted: Fri May 20, 2005 1:59 pm
by QdollarSign
one way is to use html and php combined.
Code: Select all
<html>
<body><a href="e;
Code: Select all
"e;>your link name</a></body>
</html>
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$
Posted: Fri May 20, 2005 2:32 pm
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.
Posted: Fri May 20, 2005 2:44 pm
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.
Posted: Fri May 20, 2005 2:57 pm
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
Posted: Fri May 20, 2005 3:57 pm
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.