|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
tdktank59 Smarty Rookie
Joined: 13 Feb 2008 Posts: 7
|
Posted: Thu Feb 14, 2008 2:11 am Post subject: Help? some fun stuff |
|
|
Hey,
ALlright so heres what im trying to do.
Ive got a few things i need to do in this simple script that works in php but i cant figure how to make it transfer into smarty properly. I have the logic figured out just dont know smarty all that well yet.
so here it goes
The php code
Code: | // Break apart assigned projects
$projects = split(':',$_SESSION['data']['assigned_projects']);
$total_projects = count($projects);
$sql = "SELECT * FROM projects WHERE end_time = 0 ORDER BY start_time ASC";
$result = mysql_query($sql);
if (mysql_num_rows($result) == 0)
{
report('Nothing to Display','There are currently no projects to display');
}
while ( $rows = mysql_fetch_assoc($result) )
{
$project_data[] = $rows;
}
$projects = new Smarty;
$projects->assign('page', 'index');
$projects->assign('project_data',$project_data);
// Stuff to check if the user has authentication
$projects->assign('total_projects',$total_projects);
$projects->assign('projects',$projects);
$projects->display($site_style.'/projects.tpl'); |
The Logic in php (works)
Code: |
// Lets start displaying the projects
while ( $project_data = mysql_fetch_assoc($result) )
{
// Lets setup a count for the array so we can check if the user has access to the project
for ($i=0; $i <= $total_projects; $i++)
{
// Lets actually check if they have proper authentication
if ($projects[$i] == $project_data['id'])
{
// Looks like they have authentication
echo $project_data['name'].'<br />';
}
}
} |
So i need to somehow turn that php logic into smarty logic! any help is apperciated!
The basics of the script is we have projects and you can be assigned the project in a row in the db then we explode the row value into an array thus the variable $projects it holds all of the projects you can see.
Then we get all the projects out of the database and check the project id to the users project auth list ($projects[]) and if they match then the user can see the project.
theres some other stuff int there like if the project is closed and what not so ive said the stuff that matters above! |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Feb 14, 2008 6:18 pm Post subject: |
|
|
You shold already limit the mysql query results just to the assigned projects.
Code: | // Break apart assigned projects
$projects = str_replace(':',',',$_SESSION['data']['assigned_projects']);
$sql = "SELECT * FROM projects WHERE end_time = 0 AND id IN ($projects) ORDER BY start_time ASC";
$result = mysql_query($sql);
if (mysql_num_rows($result) == 0)
{
report('Nothing to Display','There are currently no projects to display');
}
while ( $rows = mysql_fetch_assoc($result) )
{
$project_data[] = $rows;
}
$projects = new Smarty;
$projects->assign('page', 'index');
$projects->assign('project_data',$project_data);
$projects->display($site_style.'/projects.tpl');
|
In projects.tpl
Code: |
{foreach from=$project_data item=thisproject}
{$thisproject.name} <br>
{/foreach}
|
|
|
Back to top |
|
tdktank59 Smarty Rookie
Joined: 13 Feb 2008 Posts: 7
|
Posted: Thu Feb 14, 2008 9:22 pm Post subject: |
|
|
wow thanks
i didnt know that IN was part of mysql lol
Thanks a bunch! |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|