nookle Posted November 13, 2006 Share Posted November 13, 2006 I have a query in a function file that is the following and produces the listed result:$sql_query = "SELECT football_profile,basketball_profile,baseball_profile FROM profile_access WHERE mem_id='100003'";$result = $GLOBALS["DB"]->row($sql_query);$GLOBALS["smarty"]->assign("result",$result);Results: football_profile='0' basketball_profile='0' baseball_profile='6'In a separate template file, I do the following to display the results: {foreach from=$result item=result key=i name=result} {if !$result=='6'} <tr><td colspan="3"> <a href="index.php?page=account§ion={$result}">link </td></tr> {/if} {/foreach}The links end up as the following: "index.php?page=account§ion=0"My question is this, how do I write the loop function (or change my sql process) to generate the link to use the field name rather than the value, i.e., "index.php?page=account§ion=football_profile" ?Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/27109-looping-through-a-query-result-to-generate-a-link/ Share on other sites More sharing options...
nookle Posted November 14, 2006 Author Share Posted November 14, 2006 I got things working, so I am modifying my question. My array returns the following:Array ( [football_profile] => 0 [basketball_profile] => 6 [archery_profile] => 6 )I would like to generate a loop that creates links that look like the following using the array details:<a href="index.php?page=account§ion=football_profile">Football Profile</a>How do I convert the field name from 'football_profile' to 'Football Profile' for the name, but leave 'football_profile' for the link?Thanks. Link to comment https://forums.phpfreaks.com/topic/27109-looping-through-a-query-result-to-generate-a-link/#findComment-124309 Share on other sites More sharing options...
The Little Guy Posted November 14, 2006 Share Posted November 14, 2006 [code]<?php$sql_query = "SELECT football_profile,basketball_profile,baseball_profile FROM profile_access WHERE mem_id='100003'";while($row = mysql_fetch_array($sql)){ echo'<a href="index.php?page=account§ion='.$row['Column_name'].'">';}?>[/code] Link to comment https://forums.phpfreaks.com/topic/27109-looping-through-a-query-result-to-generate-a-link/#findComment-124310 Share on other sites More sharing options...
nookle Posted November 15, 2006 Author Share Posted November 15, 2006 [quote author=The Little Guy link=topic=114826.msg467674#msg467674 date=1163478615][code]<?php$sql_query = "SELECT football_profile,basketball_profile,baseball_profile FROM profile_access WHERE mem_id='100003'";while($row = mysql_fetch_array($sql)){ echo'<a href="index.php?page=account§ion='.$row['Column_name'].'">';}?>[/code][/quote]Thanks. I have the looping working now to create the links. How do I add the link name without the "_" and with first letters capitalized? It would look like the following:[code]echo'<a href="index.php?page=account§ion='.$row['column_name'].'"> Column Name </a>';[/code]which would produce:[code]<a href="index.php?page=account§ion=football_profile">Football Profile</a>[/code]Also, since the array contains information such as [football_profile] => 0, is it possible to add a second value to the array, which would be the Column Name? (Array manipulation is new territory for me.)Thanks. Link to comment https://forums.phpfreaks.com/topic/27109-looping-through-a-query-result-to-generate-a-link/#findComment-124984 Share on other sites More sharing options...
The Little Guy Posted November 15, 2006 Share Posted November 15, 2006 [code]<?php echo'<a href="index.php?page=account§ion='.$row['column_name'].'">'.ucwords(str_replace("_", " ",$row['column_name'])).'</a>';?>[/code] Link to comment https://forums.phpfreaks.com/topic/27109-looping-through-a-query-result-to-generate-a-link/#findComment-125050 Share on other sites More sharing options...
nookle Posted November 16, 2006 Author Share Posted November 16, 2006 Aha, it was the nested function that I was missing. Thanks for the help. I appreciate it. Link to comment https://forums.phpfreaks.com/topic/27109-looping-through-a-query-result-to-generate-a-link/#findComment-125587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.