Jump to content

PHP While + Template Engine?


jj20051

Recommended Posts

Ok... So I have a while() query to pull support tickets from my database. I would like to setup a system where the while() function is called inside a template file, without having the template file contain the lines of code for it.

 

Example While Function:

$open_tickets = mysql_query("SELECT * FROM support_tickets WHERE user_id='$id' && order_by='1' && ticket_status='open' ORDER BY ticket_id DESC") or die(mysql_error());
while($tick = mysql_fetch_array($open_tickets, MYSQL_ASSOC))
{
?>
<tr><td><a href="tickets.php?id=<?php echo $tick['ticket_id'].'">'.$tick['ticket_title']; ?></a></td><td><div align="center"><?php echo $tick['ticket_reply']; ?></div></td><td><div align="center"><?php echo $tick['ticket_urgency']; ?></div></td></tr>
<?php
}

 

It would be awesome if I could get all that to run off of looping variables so that the template looks like:

<?php $begin_while; ?>
<tr><td><a href="tickets.php?id=<?php echo $ticket_id; ?>"><?php echo $ticket_title; ?></a></td><td><div align="center"><?php echo $ticket_reply; ?></div></td><td><div align="center"><?php echo $ticket_urgency; ?></div></td></tr>
<?php $end_while; ?>

 

or something similar. Suggestions? I don't want to implement smarty or another template system, at least not yet... I just want something in php that can do what's described above. Of course all I'm really looking for is something that looks cleaner... Could I make the while function $tick into something smaller and place the query into the system instead of the template?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.