Twysted Posted November 13, 2014 Share Posted November 13, 2014 Ok so i have made the page to load the data and i have my tpl file loading i just can't figure out for the life of me why it is not displaying correctly. what it is displaying php for the page <?php if($Auth->isLogged()) { $aid = $Auth->loggedAid(); $limit = 10; //grab available PTC links from db output in json $db->select('*', 'ptc', 'active = 1'); if($db->returned_rows >= 1) { $username = $Auth->loggedUsername(); $time = time(); //$row = $db->fetch_assoc_all(); $smarty->assign('row', $db->fetch_assoc()); $smarty->assign('username', $username); $smarty->assign('time', $time); } else { //set var not to display ptc ads $smarty->assign("row", "No PTC are available"); } } $smarty->display('ptc_view.tpl'); ?> tpl file <!-- START content-container --> <section id="content-container" class="clearfix"> <div id="main-wrap" class="clearfix"> <div class="page_content"> <table class="table table-hover"> <tr> <th>Ad Link</th> <th>Earnings | Points</th> <th>Times Completed</th> <th>Total Visits</th> <th>Date Added</th> </tr> {foreach key=pid item=ri from=$row} <tr> <td><a href="Pages/ptcview/{$ri[0]}">{$ri[1]}</a><br/>{$ri[3]}</td> <td>{$ri[5]} | {$ri[6]} pts</td> <td>{$ri[8]}</td> <td>{$ri[7]}</td> <td>{$ri[13]}</td> </tr> {foreachelse} <tr> <td colspan="5">Sorry there are no PTC ads available right now</td> </tr> {/foreach} can someone please show me where i have gone wrong? BTW the db table does exist and there is 1 record in it. Quote Link to comment Share on other sites More sharing options...
Twysted Posted November 13, 2014 Author Share Posted November 13, 2014 I have fixed the php and it is showing there should be a row but it's not showing the data. i have not changed the tpl file anymore so what you see above is how it still is but here is the update i made to the php and also an image showing what i see. php <?php if($Auth->isLogged()) { $aid = $Auth->loggedAid(); $limit = 10; $row = array(); $db->query('SELECT * FROM ptc WHERE active = 1'); if($db->returned_rows >= 1) { $username = $Auth->loggedUsername(); $time = time(); $row = $db->fetch_assoc_all(); $smarty->assign('row', $row); $smarty->assign('username', $username); $smarty->assign('time', $time); } else { //set var not to display ptc ads $smarty->assign("row", "No PTC are available"); } } $smarty->display('ptc_view.tpl'); ?> Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 13, 2014 Share Posted November 13, 2014 $row has the entire recordset, of which, you are iterating through it. The first iteration has record 0 of the recordset, and the value is an associated array - namely the names of the columns and the data in that column for that row. Does Smarty2 allow access to an associated (hash) array's elements by an index integer? Or must we use the hash key names (the column names of the table)? Quote Link to comment Share on other sites More sharing options...
Twysted Posted November 13, 2014 Author Share Posted November 13, 2014 $row has the entire recordset, of which, you are iterating through it. The first iteration has record 0 of the recordset, and the value is an associated array - namely the names of the columns and the data in that column for that row. Does Smarty2 allow access to an associated (hash) array's elements by an index integer? Or must we use the hash key names (the column names of the table)? http://www.smarty.net/docsv2/en/language.variables.tpl#language.variables.assoc.arrays http://www.smarty.net/docsv2/en/language.variables.tpl#language.variables.array.indexes Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 13, 2014 Share Posted November 13, 2014 Please do not think that one can access an associative array by a positional index integer, nor an indexed array by anything other than a positional index integer. Try to use the column names. You should have some sort of idea what they are to line up with the HTML table's column headings. If you truly cannot know this, then you can convert the associative array into an indexed array: {foreach key=pid item=ri from=$row}{$ri = array_values($ri)} 1 Quote Link to comment Share on other sites More sharing options...
Twysted Posted November 13, 2014 Author Share Posted November 13, 2014 (edited) Please do not think that one can access an associative array by a positional index integer, nor an indexed array by anything other than a positional index integer. Try to use the column names. You should have some sort of idea what they are to line up with the HTML table's column headings. If you truly cannot know this, then you can convert the associative array into an indexed array: {foreach key=pid item=ri from=$row}{$ri = array_values($ri)} I will try your suggestion i have tried naming them but it still doesn't work. that didn't work very well did grab data but here is a screenshot Edited November 13, 2014 by Twysted Quote Link to comment Share on other sites More sharing options...
Twysted Posted November 14, 2014 Author Share Posted November 14, 2014 I will try your suggestion i have tried naming them but it still doesn't work. that didn't work very well did grab data but here is a screenshot after examining it for some time i have noticed that it is splitting the results between all the tables. I am lost as to how this is happening. some help would be appreciated. Quote Link to comment Share on other sites More sharing options...
Solution Twysted Posted November 14, 2014 Author Solution Share Posted November 14, 2014 Son Of A ...... Long pause.... i fixed it. it wasn't a foreach i needed it was a section....geesh. all i wanted was poited in the right diraction. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.