Welcome Guest, Not a member yet? Register   Sign In
URL and/or anchor from database
#1

[eluser]Unknown[/eluser]
Hey guys, I've run into a small problem, that might be more PHP than CI, but I would appreciate any help. I'm developing a basic website, formatted for the iphone to display a menu from a mySQL database. So far, so good. I've got my main view setup and it reads the records from the database beautifully. Here is the code:

Code:
<?php foreach($query->result() as $row): ?>
<li class="menu"><a href="appetizers.html"><span class="name">&lt;?php echo $row->catDesc; ?&gt;</span>
<span class="arrow"></span></a></li>
&lt;?php endforeach; ?&gt;

The problem lies in the anchor. Obviously I dont wan't all the generated links to go to appetizers.html, thats just in there for testing. I want each link to go and pull a different query, which is doable, I just have to follow the blog video tutorial. But the link in that tutorial is below the foreach statement. My goal is to have the link go to www.mydomain.com/index.php/catDesc where catDesc is the data pulled from the database. Then that view will display all the items under that category.

Does this make sense? I swear it does in my head. Smile Again, any help would be appreciated. Thanks in advance...
#2

[eluser]umefarooq[/eluser]
hi try to use CI anchor it will solve you problem.

Code:
anchor(uri segments, text, attributes)

check the user guide also

http://ellislab.com/codeigniter/user-gui...elper.html
#3

[eluser]Unknown[/eluser]
[quote author="umefarooq" date="1248344914"]hi try to use CI anchor it will solve you problem.

Code:
anchor(uri segments, text, attributes)

check the user guide also

http://ellislab.com/codeigniter/user-gui...elper.html[/quote]

Thanks for the quick response. I did try that, but I cant seem to get the uri segments to be dynamically pulled from the database. also, i need the display text to be dynamically pulled from the DB aslo. Here's what I have inputted, which obviously isn't working.
Code:
&lt;?php foreach($query->result() as $row): ?&gt;
<li class="menu">&lt;?=anchor('&lt;?=$row->catDesc', '&lt;?=$row->catDesc');?&gt;</li>
&lt;?php endforeach; ?&gt;
So my question is this, can i put php/sql commands inside the anchor tag? Also, can I add css styles inside it also? similar to my html code in the first post?

Also, off topic, but that's an interesting username, umefarooq. In my language it means "Mother of Farooq" or "Farooq's Mother." Just kinda interesting...
#4

[eluser]David Johansson[/eluser]
Code:
&lt;?php foreach($query->result() as $row): ?&gt;
<li class="menu">&lt;?=anchor($row->catDesc, '<span class="name">'.$row->catDesc.'</span>', 'style="color: black;"');?&gt;</li>
&lt;?php endforeach; ?&gt;
the style-argument is just an example.




Theme © iAndrew 2016 - Forum software by © MyBB