Jump to content


Photo

Read from MySql database and create link


  • Please log in to reply
3 replies to this topic

#1 Sirhc

Sirhc
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 31 August 2006 - 04:53 PM

Hi,

I am trying to read a information from a database (categories) and display this info as a link.
Onclick the category will again read the subcategory belonging to this category from the database.

What I am missing is how to take the info I got from the database and convert this into a link.
See my script hereunder: (the last line is what I am missing).


$id_parent=$_GET['id_parent'];
$conn = mysql_connect(host, user, password);
mysql_select_db(database);
$sql = mysql_query("SELECT title FROM `dir_categories` WHERE id_parent='$id_parent' ");
while($result = mysql_fetch_array($sql)) {
echo <a href="title.php"> $result  </a>; }

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 31 August 2006 - 04:58 PM

You're almost there use this:
echo '<a href="title.php">' . $result['title'] . '</a>';


#3 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 31 August 2006 - 05:18 PM

try
echo '<a href="title.php?id_parent='.$result['title'].'"> ' . $result['title'] . ' </a>';


#4 Sirhc

Sirhc
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 31 August 2006 - 05:38 PM

You Guys area great!!
It works thanks.

But I still have one small problem.
The id_parent changes depending on the info I read from Mysql.
Do I just aplly an if statement for the id_parent?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users