Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query 2 fields from MySQL using one to render the other as a hyperlink

Status
Not open for further replies.

KitM

MIS
Apr 26, 2002
2
US
Hi,

First, absolutely great site. Now:

I want to have PHP code on a page that will query a MySQL db, "extract" two fields (Link, LinkName) and render the "LinkName" field on the page with the "Link"(hidden) utilized as the hyperlink attached to the rendered LinkName - i.e.: a menu fed by a MySQL table. I've done this with MS Access/PHP. If you can tell me the where I might find the cross-reference Access/MySQL/PHP coding key, I could probably do this myself.

Thanks, and, again, GREAT SITE!

KitM
KitM@FirstEquipment.com
 
it should be the same...using sql to take the data from the db...just point to the mysql db instead...it is actually easier as no ODBC is needed...php supports mysql natively...

generally the connection string i use is in a separate file called dbconn.php which i just include in the page to be executed.

<?
$username = &quot;root&quot;;
$pwd =&quot;&quot;;
$host = &quot;localhost&quot;;
$dbname = &quot;gulfstream&quot;;



//connect to db
//$conn=mysql_connect($host, $username, $pwd) or die (&quot;Unable to connect to database&quot;);

if (!($conn=mysql_connect($host, $username, $pwd))) {
printf(&quot;error connecting to DB by user = $username and pwd=$pwd&quot;);
exit;
}
$db=mysql_select_db($dbname,$conn) or die(&quot;Unable to connect to database1&quot;);
?>

hth Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Hi,

First, thanks for your answer:however the main crux of the question is stated in the title,&quot;Query 2 fields from MySQL using one to render the other as a hyperlink&quot;. I included the &quot;query a MySQL db&quot; entry as part of a succession of procedures. The connection to a MySQL db is not my main problem - that is,&quot;extract&quot; two fields (Link, LinkName) and render the &quot;LinkName&quot; field on the page with the &quot;Link&quot;(hidden) utilized as the hyperlink attached to the rendered LinkName - i.e.: a menu fed by a MySQL table.&quot;

That's what I need to know.

I do appreciate this first and all responses to my questions, but, in this case, the main part of the problem was missed.

Thanks, again, for your time and trouble.

Peace, again,
KitM
 
you need something like this (check code as I'm not able to myself- not at home)

$result = mysql_query (select * from #####)

while ($a_row = mysql_fetch_array($result))
print &quot;<a href=\&quot;$a_row[links]\&quot;>$a_rows[linknames]</a>&quot; Sometimes, when my code just won't behave, I take it outside and make it listen to britney spears music, and when it comes back it's really well behaved. I wonder if it's suffering from post tramatic stress syndrome now..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top