Jump to content

Looping through a query result to generate a link


nookle

Recommended Posts

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&section={$result}">link
      </td></tr>
    {/if}
  {/foreach}


The links end up as the following: "index.php?page=account&section=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&section=football_profile" ?


Thanks for the help!
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&section=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.
[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&section='.$row['Column_name'].'">';
}
?>[/code]
[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&section='.$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&section='.$row['column_name'].'"> Column Name </a>';[/code]

which would produce:

[code]<a href="index.php?page=account&section=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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.