Jump to content

Functions generating PHP? Similar to Wordpress' theLoop??


gcb

Recommended Posts

I'm having a bit of a problem wrapping my head around the following:

 

I want to be able to call rows of information from my database using as little code on the front-end document as possible; that (I figure) would look a little something like the following:

 

<html>
<blahblahblah>

...

<?php dbQuery("SELECT * FROM `table` WHERE `id`='24573' LIMIT 1", "order");?>

Order #<?=$order['id'];?> was sold to <?=$order['buyer'];?> on <?=$order['purch_date'];?> by <?=$order['associate'];?>

<? endquery(); ?>

 

and the function might look like

 

function dbQuery($query,$var){
     $q = mysql_query("".$query."");
     
     ${$a} = $var;

     //some other stuff happens

}

 

While that "some other stuff happens", I want the function to spit out (or at least start) the

 while(${$a} = mysql_fetch_array($q){ 

which starts the While loop that populates my information...But my problem is if I put the While(){part at the end of the function, the function just thinks its ending bracket is actually the ending bracket of the While loop.

 

I guess at the end of the day, I want my dbQuery function to execute the mysql query that's specified as the first parameter, and then eventually assign the array name whatever is set as the second parameter...so I can use it later. I also plan to have up to 5 of these running on a single page at a time...and then close each dbQuery function off with a nice little <? endquery(); ?> or something...

 

To me, it seems like I want to do something like the Wordpress TheLoop(). I've written for Wordpress enough to know my way around the system....just never really bothered to take a look under the hood pick apart what really makes WP tick.

 

Any idea on whats going on, or if I should just not be lazy and write in those extra 3 lines of code...or do I need to better explain myself? Can a function maybe return a chunk of code like it does with variables??

 

Any help is pushing me in the right direction. Thanks!

~G

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.