![]() |
Looping templates help
I have referred to this and this
Now, in my PHP file, I have this:- PHP Code:
I have simply copied the foreach part from the above mentioned links. What arguments I need to pass to foreach and how ? Do I need to do something before it also ? Please guide me on how to correct the above code. Thank You |
<a href="http://us3.php.net/foreach" target="_blank">http://us3.php.net/foreach</a>
|
You don't need foreach... unless you are fetching an array from the database.
PHP Code:
|
yes thanks opserty, I had figured it out earlier with the help of the link in post 2.
can you please tell me:- Say I have a vbpage called mypage.php , and I have 2 subpages in it called mypage.php?do=this and mypage.php?do=that. So, in total there are 3 associated templates (1 for main page and 2 for subpages). Now, whenever I visit the subpages I notice that the queries executed in the main page are also being executed in the sub-pages, and the template of the main page is also being used/called unnecessarily in sub-pages (I see this from debug info). BUT its not vice-versa. How should I resolve this ? Thank you |
It is probably the way you have written your conditions, make sure you have a default condition if the request string is empty.
PHP Code:
|
oh wow, thanks danny ! it worked great. Yes, I did not had a default condition if the request string was empty.
alright one more thing plz... How do I append a variable to a URL from within PHP? see I have this code:- PHP Code:
Currently it does not show the values in the URL (its blank like cat=), but on echo the variable does throw the correct values. Thank You |
First try concatenating the string...ex... "?do=search&cat=".$category."&"
Also use the URLencode function before you combine the string to form the url http://us3.php.net/urlencode |
where do I put this line "?do=search&cat=".$category."&" in the php code above ?? How to append to URL ?
|
On the code for the link to the page - it needs to have the variables in the URL there.
|
sorry I don't understand stilll ..
see I have a form (in template) whose action is "page.php?do=search" via post method. On hitting Submit button it simply goes to the below code, executes the query and all, and results fine. PHP Code:
Now, my problem is that the URL of the results page displays page.php?do=search and NOT appending the variables, how do I do it ??? how do i append $category and $order values to it ?? Thank You |
oh ok lol... Change the forms method from 'POST' to 'GET'. Aslo change the action from 'page.php?do=search' to just 'page.php' and add a hidden input with the name 'do' that has the value set as 'search'.
|
ahh.. thank you so much !! I had used get method earlier but did not change action or added that hidden field. It does work now. You solved a big problem of mine.
alright.. one more thing, GET method adds all the fields in the URL. How do I remove some ? for ex. that long securitytoken value also appends now. I must use that but do not want to show that in URL. Thank You |
You do not need the security tokens in a 'get' form.
|
oh great.. everything works now !!
few more things plzz :- 1. How do I make URL parameters mandatory or say redirect to main page or give an error message. Say, I have a page with a form that works only like page.php?do=edit&uid=50. Now, I do not want it to be opened/viewed like page.php?do=edit as it shows a blank form. 2. I wanted to know, when is $db->close(); used ? |
Judging by your url, I have one comment about it. The url makes it seem as if your editing something on the page, I would go back to using the POST request or implement your own CRSF protection on the GET request if your page allows for editing of anything important. VB's CSRF does not cover get requests only post requests.
1. PHP Code:
|
yes I am already using POST method there for the above "edit form page" and have implemented the CSRF protection.
1. Great.. DONE ! 2. In my page, its like this:- PHP Code:
Thank You |
From what I understand you do not need to use that unless your accessing the database in your code. And all that function does is clean up and close the connection to the database.
If Im wrong someone may correct me. |
but I am accessing database in my code, lot of queries are there !
Also, please tell, is there a way to insert escape charaters in the database by NOT using $vbulletin->db->escape_string_like(htmlspecialchars_uni($variable )) in the query, as it makes it very long when there are many fields. Thanks |
All times are GMT. The time now is 11:39 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|