Help with own code

Discussion forum for MOD Writers regarding MOD Development.
porfavor
Registered User
Posts: 108
Joined: Sat Aug 04, 2007 3:28 pm

Help with own code

Post by porfavor » Tue May 27, 2008 9:32 pm

Hi,

I am new to php/mysql. I wanted to make a little script which reads some data from the DB and prints it.
The php file looks like that:

Code: Select all

<?php
/**
*
* @package phpBB3
* @version $Id: memberlist.php 8479 2008-03-29 00:22:48Z naderman $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);


// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup(array('memberlist', 'groups'));


// Output the basic page

page_header('Medaillen');


$template->set_filenames(array(
	'body' => 'medals.html')
	);


$werte="SELECT Edelmetall,Name,Sportart FROM phpbb_medalwinner;";
$ergebnis = mysql_query($werte) OR die(mysql_error());
        
 
    while($row = mysql_fetch_assoc($ergebnis)) {
         $row['Edelmetall']."&nbsp;".$row['Name']."&nbsp;".$row['Sportart']."<br />";
  }

	$template->assign_vars(array(
			'EDELMETALL'			=> $row['Edelmetall'],
			'NAME'		=> $row['Name'],
			'SPORTART'		=> $row['Sportart'],
			));

 

page_footer();

?>
the template:

Code: Select all

<!-- INCLUDE overall_header.html -->
<h2>Medaillengewinner Peking '08</h2>
<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>

   <div class="content">
      <p>
<table width="1200" align="center" border="3" bordercolor="blue">       
<tr>
<th width="100"><h2>Medaille</h2></th>
<th width"550"><h2>Name</h2></th>
<th width="550"><h2>Sportart</h2></th>
</tr>
<tr>
<td width="100"><h3><center>{EDELMETALL}</center></h3></td>
<td width="550"><h3><center>{NAME}</center></h3></td>
<td width="550"><h3><center>{SPORTART}</center></h3></td>
</table>
      </p>
   </div>

   <span class="corners-bottom"><span></span></span></div>
</div>



<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->
However, nothing is displayed in the table, although there is an entry in the db.
I am not sure what is wrong.
I hope anyone here is able to help me solving that.

Thanks!

porfavor
Registered User
Posts: 108
Joined: Sat Aug 04, 2007 3:28 pm

Re: Help with own code

Post by porfavor » Wed May 28, 2008 6:48 pm

nobody an idea?
I just can't figure it out as I am not expirienced.

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51890
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Help with own code

Post by Brf » Wed May 28, 2008 7:01 pm

You are assigning your template variables outside of the $row loop. By the time you are doing the assigning, you have run all the way through your table, and now have an empty end-of-data $row.

porfavor
Registered User
Posts: 108
Joined: Sat Aug 04, 2007 3:28 pm

Re: Help with own code

Post by porfavor » Wed May 28, 2008 7:39 pm

Did I understand correctly?Is it supposed to be like that?

Code: Select all

while($row = mysql_fetch_assoc($ergebnis)) {
         $row['Edelmetall']."&nbsp;".$row['Name']."&nbsp;".$row['Sportart']."<br />";
 $template->assign_vars(array(
         'EDELMETALL'         => $row['Edelmetall'],
         'NAME'      => $row['Name'],
         'SPORTART'      => $row['Sportart'],
         ));
  }

 
or have the template vars to be before the while loop?

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51890
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Help with own code

Post by Brf » Wed May 28, 2008 7:41 pm

Yes.
Except that this serves no purpose:

Code: Select all

         $row['Edelmetall']."&nbsp;".$row['Name']."&nbsp;".$row['Sportart']."<br />"; 

porfavor
Registered User
Posts: 108
Joined: Sat Aug 04, 2007 3:28 pm

Re: Help with own code

Post by porfavor » Wed May 28, 2008 9:47 pm

well, how can I assign $row then if not existing?

I will try it in a few days, anyway.

Thanks

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51890
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Help with own code

Post by Brf » Thu May 29, 2008 10:26 am

That statement is not doing anything. It is not assigning $row.

This statement is assigning $row:

Code: Select all

$row = mysql_fetch_assoc($ergebnis)

porfavor
Registered User
Posts: 108
Joined: Sat Aug 04, 2007 3:28 pm

Re: Help with own code

Post by porfavor » Sun Jun 01, 2008 6:04 pm

ok thanks, works.

However, it does only print the last entry in the DB. how can I display all of them?

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51890
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Help with own code

Post by Brf » Mon Jun 02, 2008 11:16 am

You will need to use template block variables to display more than one.

porfavor
Registered User
Posts: 108
Joined: Sat Aug 04, 2007 3:28 pm

Re: Help with own code

Post by porfavor » Mon Jun 02, 2008 3:00 pm

ok will try this, thanks

edit: silly question:

how do I do this?

I tried this:

Code: Select all

$template->assign_block_vars('tabelle', array(
			'EDELMETALL'			=> $row['Edelmetall'],
			'NAME'		=> $row['Name'],
			'SPORTART'		=> $row['Sportart'],
			));
no output

porfavor
Registered User
Posts: 108
Joined: Sat Aug 04, 2007 3:28 pm

Re: Help with own code

Post by porfavor » Thu Jun 05, 2008 7:02 pm

any ideas? :(

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51890
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Help with own code

Post by Brf » Thu Jun 05, 2008 7:20 pm

What is in your template?

porfavor
Registered User
Posts: 108
Joined: Sat Aug 04, 2007 3:28 pm

Re: Help with own code

Post by porfavor » Sat Jun 07, 2008 10:50 pm

this is the current template, will change it of course but I first want to make sure the code works correctly.

Code: Select all

<!-- INCLUDE overall_header.html -->
<h2>Medaillengewinner Peking '08</h2>
<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>

   <div class="content">
      <p>
<table width="1200" align="center" border="3" bordercolor="blue">       
<tr>
<th width="100"><h2>Medaille</h2></th>
<th width"550"><h2>Name</h2></th>
<th width="550"><h2>Sportart</h2></th>
</tr>
<tr>
<td width="100"><h3><center>{EDELMETALL}</center></h3></td>
<td width="550"><h3><center>{NAME}</center></h3></td>
<td width="550"><h3><center>{SPORTART}</center></h3></td>
</table>
      </p>
   </div>

   <span class="corners-bottom"><span></span></span></div>
</div>



<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51890
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Help with own code

Post by Brf » Sun Jun 08, 2008 11:53 am

porfavor wrote: no output
So where is your block?
You need the block defined with

Code: Select all

<!-- BEGIN tabelle -->
{tabelle.EDELMETALL}
etc...

User avatar
stickerboy
Former Team Member
Posts: 7349
Joined: Mon Mar 29, 2004 2:27 pm
Location: Airdrie, UK (127.0.0.1)
Name: Kenny Cameron
Contact:

Re: Help with own code

Post by stickerboy » Sun Jun 08, 2008 2:52 pm

Moved to MOD Writers from Support
I'm a web-designing code-decrypting tech-support musician
|| Twitter || Flickr || phpBB Snippets ||
Formerly known as cherokee red

Locked

Return to “[3.0.x] MOD Writers Discussion”