Not signed in (Sign In)
Welcome, Guest

Did you know that there is a whole world of functionality you're not seeing? If you have an account, sign in now.

If you don't have an account, apply for one now.

Bottom of Page
Savant2: How do I use the "while" php function grabbing data from the database
  1.  
1 to 4 of 4
Jul 22nd 2007
How do I use the "while" php function grabbing data from the database.
The php code creates a new table row displaying data from the database.
How do I implement this into my Savant template.
I've tried using variables but It dont work.

================
Code
================
<?php
include "config.php";
if ($logged[username] && $logged[level] == 5)
{
echo "$logged[username]";
$getbuttons = "SELECT * from affiliates where clan = '$logged[clan]' ORDER by hitsout desc";
$getbuttons2 = mysql_query($getbuttons) or die("Could not get buttons");
print "<table border='1'>";
print "<tr><td>Button link</td><td>Hits out</td><td>Edit</td><td>Delete</td></tr>";
while ($getbuttons3 = mysql_fetch_array($getbuttons2))
{
print "<tr><td>
<A href='$getbuttons3[url]' target='_blank'><img src='$getbuttons3[image]' border='0'></a></td>";
print "<td>$getbuttons3[hitsout]</td><td><A href='edit.php?ID=$getbuttons3[affid]'>Edit</a></td>";
print "<td><A href='delete.php?ID=$getbuttons3[affid]'>Delete</a></td></tr>";
}
print "</table>";
}
else
{
//the user's level is not 5! They cannot view this page
echo "<meta http-equiv="Refresh" content="0; URL=mustlogin.php"/>Thank You! You will be redirected"; };
?>

==================
affiliates_editall.php
==================
<?php
include "config.php";

//Load the Savant class file and create an instance
require_once 'Savant2.php';
include("config.php");
$tpl = &new Savant2();

//Create a title and template path
$pagetitle = "$titlebar";
$tpl->addPath('template', "templates/$templatedir");
$affiliates = ("affiliates.php");
if ($logged[username] && $logged[level] == 5)
{
echo "$logged[username]";
$getbuttons = "SELECT * from affiliates where clan = '$logged[clan]' ORDER by hitsout desc";
$getbuttons2 = mysql_query($getbuttons) or die("Could not get buttons");
print "<table border='1'>";
print "<tr><td>Button link</td><td>Hits out</td><td>Edit</td><td>Delete</td></tr>";
while ($getbuttons3 = mysql_fetch_array($getbuttons2))
{
print "<tr><td>
<A href='$getbuttons3[url]' target='_blank'><img src='$getbuttons3[image]' border='0'></a></td>";
print "<td>$getbuttons3[hitsout]</td><td><A href='edit.php?ID=$getbuttons3[affid]'>Edit</a></td>";
print "<td><A href='delete.php?ID=$getbuttons3[affid]'>Delete</a></td></tr>";
}
print "</table>";
}
else
{
//the user's level is not 5! They cannot view this page
echo "<meta http-equiv="Refresh" content="0; URL=mustlogin.php"/>Thank You! You will be redirected"; };

//Assign values to the Savant instance
$tpl->assign('whatami', htmlspecialchars_decode("$whatami") );
$tpl->assign('stylename', $stylename);
$tpl->assign('affiliates', $affiliates);
$tpl->assign('pagetitle', $pagetitle);

//Display a template using the assigned values
$tpl->display('mustlogin.tpl.php');


?>

======================
affiliates_editall.tpl.php
======================
<html>
<head>
<title><?php $this->_($this->pagetitle) ?></title>
<link href="templates/<?php $this->_($this->stylename) ?>" rel="stylesheet" type="text/css" />
<!-- the above code gets the stylesheet. change it via config.php -->
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
<center>
<? include ("config.php"); ?>
<table width="790" class="bordered" cellspacing="0" cellpadding="0" >
<tr>
<td>
<?php include $this->loadTemplate('header.tpl.php') ?>
</td>
</tr>
<tr>
<td class="header"><p>Modify your affiliates</p></td>
</tr>
<tr>
<td class="tablelight"><p>
<br>When somebody browses this website logged out, they can see the affiliates of all the clans.
<br>
<br><a href="affiliates_add.php">Add an 88x31 affiliate</a>


<table>
<tr><td>
<A href='$getbuttons3[url]' target='_blank'><img src='<?php $this->_($this->buttonimage) ?>' border='0'></a></td>
<td>$getbuttons3[hitsout]</td><td><A href='edit.php?ID=$getbuttons3[affid]'>Edit</a></td>
<td><A href='delete.php?ID=$getbuttons3[affid]'>Delete</a></td></tr></table>



<br><br>


</p>



</td>
</tr>
<tr>
<td>
<?php include $this->loadTemplate('footer.tpl.php') ?>
</td>
</tr>
</table>


</center>
</body>
</html>
Jul 23rd 2007
For one, you can't access global variables like $getbuttons3 from inside the template. Assign it to a template variable from outside.

You want to give your template only the most simple data structures possible, so that so that the logic within the template (e.g. looping) is as simple as can be.

Also see the complex example: http://phpsavant.com/yawiki/index.php?area=Savant2&page=StartVars#toc2
Jul 23rd 2007
ive tried the complex example
it requires i use pear db to connect to my database
but that method is too complex and confusing
Jun 29th 2010
Energy Driving
As an instructor, this can end up being a challenge to obtain college students to operate upon chipping and putting the [url=http://www.pickgf.com/] Discount golf clubs[/url]—however, they might fall anything to become able in order to invest period at the range working upon their golf tee photos! Driving the ball by the [url=http://www.pickgf.com/TaylorMade-R7-CGB-Max-Fairway-Wood-1025.html]TaylorMade R7 CGB Max Fairway Wood[/url] longer and straighter is actually the ultimate goal with regard to almost all, and there’s no membership they would not purchase the [url=http://www.pickgf.com/Titleist-2010-AP2-Irons-3-9P-1181.html]titleist 2010 ap2 irons[/url] in the event that they believed this might assist them generate the ball simply regarding instance. Although that goal may end up being a [url=http://www.pickgf.com/TaylorMade-R9-Irons-4-9PAS-1048.html]TaylorMade R9 Irons[/url] bit from reach, there’s without doubt that all of us all can enhance the driving just by making relatively basic adjustments to your method. A correct [url=http://www.pickgf.com/Callaway-X-24-HOT-Irons-4-9PAS-3349.html]Callaway X-24 HOT Irons[/url] is actually critical in order to giving a person a chance in order to generate the ball along with maximum energy. ishiner
  1.  
1 to 4 of 4
Top of PageBack to discussions