View Full Version : Smarty / PHP help
alain76
09-12-2005, 03:24 PM
I'm trying something with phpLD that I probably shouldn't be trying.
But I'm stubborn that way.
I have one (phpLD) database full of restaurants and one database with restaurant reviews.
Now I'd like phpLD to check if the restaurant name exists in the review database, but I can't seem to find the proper variable name :(
The Smarty variable is {$link.TITLE}, but how can I use that in PHP ?
If somebody can point me in the right direction I can take it from there.
yktan
09-13-2005, 09:32 AM
Hi alain76, I think what you want to do should be done in the php that uses the template instead of the template itself.
alain76
09-13-2005, 10:14 AM
Possibly, but I'll still need a variable with the name/title of the link to query the review database...
*Thinks*
Or... I need to query the database, store the results in an array and use that array in Smarty.
That could work too, right ?
yktan
09-14-2005, 07:48 AM
Hi alain76,
Are you talking about the main directory index?
If so, just open index.php (in the root directory of PHPLD) and insert your code before the following code:
Content visible to registered users only.
$links is an array with rows from the table pld_link.
An example of what you might want to do to do a loop and go through the array to check for restaurant reviews and assigning a count (I am assuming you want to count the number of reviews) variable back to the array. Do something like:
Content visible to registered users only.
Now you will have an extra field in the links called "REVIEW_COUNT". Now open templates\link.tpl and add the following code somewhere to show the count:
Content visible to registered users only.
I hope the example will serve your purpose.
Regards,
York Kie
alain76
09-14-2005, 08:32 AM
Thanks !
But that didn't help.
I've never been great with arrays and the foreach loop, so I'm assuming it's my own fault that I'm not getting your code to work.
Here's what I changed it into:
(I changed your 'link' to '$link', since it's a variable... plus PHP gave an error about it :) )
Content visible to registered users only.
I added the "script" line to see if the foreach loop was actually doing anything, since I wasn't getting any results.
And well... it's not doing anything.
It's not returning any results.
*starts crying in a corner*
edit: FYI: what I'm actually trying to do is get the 'score' ($review_score) from the review to get listed somewhere near the link.
Once I have the variable I can place it myself (I'd better !).
yktan
09-14-2005, 09:15 AM
Hi alain76, you're right, it's supposed to be $link.
Can you try this out for me:
Content visible to registered users only.
Can you kindly reply with the output that the above code generates?
Thanks,
York Kie
alain76
09-14-2005, 10:09 AM
No output at all, I'm afraid.
So that means that it CAN connect to the 'knoopjel' database, but the FOREACH loop isn't working ?
yktan
09-14-2005, 10:15 AM
Hi, something is seriously wrong. Do you mind pasting the code for the whole php file here or email it to me?
alain76
09-14-2005, 10:36 AM
Content visible to registered users only.
If I recall correctly, the only other addition I made to this code is add the 'prepare meta' thingie that Apostle made for meta keywords.
Content visible to registered users only.
yktan
09-14-2005, 10:53 AM
No output at all? This is really weird.
Could you try this for me?
Content visible to registered users only.
alain76
09-14-2005, 11:12 AM
I got output !
http://www.knoopjelos.nl/alain/
http://www.knoopjelos.nl/alain/Noord_Brabant/
http://www.knoopjelos.nl/alain/Noord_Brabant/Boxtel/
At first I only checked the 2nd link (since there's also a link there).
Thanks A LOT for your time ! I can take it from here.
Any Javascript, XHTML or PHP you need help with ? :)
yktan
09-14-2005, 11:14 AM
Hi alain76, glad that it's working for you now. Thanks for offering your skills, I might call on them one day! :)
Regards,
York Kie
alain76
09-14-2005, 11:35 AM
Content visible to registered users only.
Feel free to do so !!
If anybody's interested; here's my final code...
index.php:
Content visible to registered users only.
link.tpl:
Content visible to registered users only.
I know it's not perfect yet (especially with the queries), but it's working.
I'll clean it up later.
And the result:
http://www.knoopjelos.nl/alain/Noord_Brabant/Boxtel/
vBulletin® v3.8.0, Copyright ©2000-2012, Jelsoft Enterprises Ltd.