Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
php with sql querry help please
Old 01-08-2006, 11:36 PM php with sql querry help please
Junior Talker

Posts: 1
Trades: 0
hello again.
I have had to start from scratch as the code I was attempting to use was cluttered, mixed, and had many cominations of other scripts included that were not needed..
Here is my new code..
Code:
// phpBB stuff
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.' . $phpEx);
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
 if ( !isset($HTTP_GET_VARS['action']) || $HTTP_GET_VARS['action'] == "list" ) 
 { 
    $template->set_filenames(array( 
    'body' => 'clans_list_body.tpl') 
    ); 
  include($phpbb_root_path . 'includes/page_header.' . $phpEx);
 }
 
    $this_title = $lang['clans_title_clans_list']; 
 
    $sql = "SELECT clan_id, clan_name, clan_leader, clan_members 
                FROM " . CLANS_TABLE . " 
                    WHERE clan_members = '1' 
                ORDER BY clan_name"; 
   if ( !($result = $db->sql_query($sql)) ) 
   { 
      message_die(GENERAL_ERROR, 'Error retrieving data', '', __LINE__, __FILE__, $sql); 
   } 
        return ( $row = $db->sql_fetchrow($result) );
As you can see this does nothing more than a db querry gathering the information I need...
What I need help with is the next line of code .. I want it to output to the tpl file a table:
<==Table header==>
Name / / Leader / / Members
clan_name / / clan_leader / / (no=None / yes=link to clan_member_list.php)
thank you and I hope this isnt asking too much.. (of course I will always be back for more ha ha ha
caspert_ghost is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-09-2006, 01:51 PM
KML9870's Avatar
One Bad Mamma :-)

Posts: 5,489
Name: Kandi
Location: Western NY
Trades: 0
You need something along the lines of:

PHP Code:
$result mysql_query($sql)
or die(
mysql_error());
 
 
 
while (
$row mysql_fetch_array($result))
{
extract($row);
echo 
" Your table info & formatting \n";
 

__________________
~~Kandi~~

Please login or register to view this content. Registration is FREE


KML9870 is offline
Reply With Quote
View Public Profile
 
Old 01-09-2006, 06:14 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
If you are dealing with template systems, you will need to either a) put ALL the HTML for the whole table into one massive string variable, and assign that to a template variable with something like
PHP Code:
$longstringwithallthehtmlinit "<table><tr><td>Your table here</td></tr></table>";
$template->assign_vars(array(
    
'WHOLE_TABLE' => $longstringwithallthehtmlinit
          
)
);

$template->pparse('body'); 

and then display that by putting {WHOLE_TABLE} into the template file where you want the table to be.

Or b) you can go the slightly more complex but nicer route which is to build up the table row by row into the template:

PHP Code:
//Database query here

while ($row $db->sql_fetchrow($result))  {
  if(
$row['members'] == "No") {
    
$member_link "None";
  }
  else {
    
$member_link "<a href=\"members.php?clan=".$row['clan_id']."\">Members</a>";
  }
  
$template->assign_block_vars('tablerow', Array(
    
'CLAN_NAME' => $row['clan_name'],
    
'CLAN_LEADER' => $row['clan_leader'],
    
'MEMBERS' => $member_link ) );
}

$template->pparse('body'); 
and then put this into the template like this:

Code:
<table><tr><th>Clan Name</th><th>Clan Leader</th><th>Members</th></tr>
<!-- BEGIN tablerow -->
<tr><td>{tablerow.CLAN_NAME}</td><td>{tablerow.CLAN_LEADER}</td><td>{tablerow.MEMBERS}</td></tr>
<!-- END tablerow -->
</table>

Please note that I've guessed at a lot of things and you will need to fill in the actual values, filenames and so that exist on your site instead of the ones I've filled in. Also note that all of this is based on my knowledge of the template system that phpBB uses (since it looks very similar), but your CMS may behave slightly differently.

Let us know how you get on with this and if you want further explanation (black variables in templates are tricky).
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)

Last edited by 0beron; 01-09-2006 at 06:17 PM..
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Reply     « Reply to php with sql querry help please
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.45743 seconds with 12 queries