Categories > TinyButStrong general >

html links back to database

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Ivor Humphreys
Date: 2006-02-21
Time: 01:21

html links back to database

Is there a way of achieving this ( http://www.runoffbusiness.com/news.asp ) using TBS?

The table here shows two fields from each record (title and date). The title field is a
link which returns the id of the record back to the database in order to show the
record in full by (title, date and now main text field - the news story itself) on a
separate page.

Ivor Humphreys.
By: Skrol29
Date: 2006-02-21
Time: 02:08

Re: html links back to database

Hello,

Yes, its seems quite easy to have this done with TBS.
Two templates : one for the list, one for the detail.

The list merging can be done like the example with data-Mysql or like the TBS testimonial wich is downloadable.

If you have more questions, you can ask.
By: Tom
Date: 2006-02-21
Time: 02:10

Re: html links back to database

Assuming ;-) you are currently getting the link info form a query and the id fieldname is 'id' then TBS html template code would look like...
<a href="newsitem.asp?id="[blk.id]">LCL to advise Alea</a>
Yes, it is really that simple!
HTH
By: Ivor Humphreys
Date: 2006-02-21
Time: 09:43

Re: html links back to database

Thanks for your quick responses. Much appreciated.

I'd tried that in the template but how do I feed the id info back into the next SELECT call:

newsitem.php is:
<?php
include_once('tbs_class.php') ;
$cnx_id = mysql_connect('localhost','user','password') ;
mysql_select_db('databasename',$cnx_id) ;
$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('row.html') ;
$TBS->MergeBlock('blk1',$cnx_id,'SELECT itemname, itemdate, itemtext FROM tbl_news WHERE id=***') ;
mysql_close($cnx_id) ;
$TBS->Show() ;
?>

IH
By: Tom
Date: 2006-02-21
Time: 12:13

Re: html links back to database

The 'id' var is returned as a GET variable in the returning URL.
If you do not have GLOBALS ON then you need to explicitly get the var/value info
So at the top of your script
extract($_GET);
// now the var $id is available in this script

$sql = "SELECT itemname, itemdate, itemtext FROM tbl_news WHERE id=$id ";
// etc...

HTH
By: Ivor Humphreys
Date: 2006-02-21
Time: 12:42

Re: html links back to database

Tom

Thank you so much. I'm used to using ASP/VBScript with Access databases and
PHP/MySQL is new to me. I'm so glad to have discovered TBS.

Kind regards,

Ivor
By: Tom
Date: 2006-02-21
Time: 13:22

Re: html links back to database

Ivor,
The learning curve's not too bad if you use good examples to learn from.

TBS 'job one' is to got through ALL of Skrol's examples at
http://www.tinybutstrong.com/examples.php
review both the PHP and template source code. Doing trhat will save you many hours of learning TBS and PHP/MySQL too.

If it helps, I have a few PHP/MySQL applications that I converted to TBS  + ezSQL (another really great tool that integrates with TBS). There's source code shown also.
See http://tomhenry.us/tbs/
By: Skrol29
Date: 2006-02-21
Time: 13:24

Re: html links back to database

There are sevral ways to do it.
For example, you can create a new script which assumes to have a parameter 'id' given in its URL (like the site you've given). Then you just have to get this value and open a new template to merge only one record.

Another way is to use the same PHP script to do both the list and the detail. Depending to the prensence of parameter 'id' or not, you open the template 'row.html' or 'detail.html' and do the merges that go with.