Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Ty Schenk
iOS Development Techdegree Graduate 16,269 PointsPlease i need Help with PHP Script.
Hey everybody,
I am currently working on a script for some people and i am completely stuck, i have no idea how i am going to complete this. Basically i need a script that prints out a html code line for every mysql row that i have. The MySQL results should be a list of "Tags" so The HTML code line looks like this :
<div class="list-block"><div class="content-block-title"><?php $tag = "**MYSQL RESULT TAG HERE**"; echo $tag;?></div><ul><li><?php include('script.php');?></li></ul></div><br>
I have tried a for each and a while loop and i can't figure out how to get it working.
Any help would be great. Thanks.
2 Answers
Robert Zeno
4,660 PointsHi Ty,
Using a while loop to iterate over the mysql result will be your best option.
Try setting you mysql_result to a variable and do a while loop like so:
<?php while ( $item = mysql_fetch_assoc($mysql_result) ): ?>
print out your data using associated column names as keys
<?php endwhile; ?>
Robert
Ty Schenk
iOS Development Techdegree Graduate 16,269 PointsIt work great! Thanks for the help i greatly appreciate it.
Ty Schenk
iOS Development Techdegree Graduate 16,269 PointsTy Schenk
iOS Development Techdegree Graduate 16,269 PointsThank for the reply, I will try this and updated the here after