473,788 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

include name from variable name? help?

Hi

This may be simple to solve, but I can't seem to do it :(

I am trying to generate an include name on an image gallery page from
a variable name.
By this I mean I already have a numeric value set the variable
$imageCat.

What I want to do is pull in an external include file using the
variable as the file name. So if $imageCat is set to 2 I want to bring
in 2.html ($imageCat.html ).

I can hard code each include request as such:

{if $imageCat=="2"}
{php}
include ("2.php");
{/php}
{/if}

But I am dealing with oodles of categories so this file would be huge.
A dynamic option would be very cool but I just can't seem to get my
syntax right.

If anyone could give me even a vague pointer; I would be sooooo
greatful.

Many thanks

Mr M
Dec 2 '07 #1
7 1696
A loop might a be idea if everything is a number .

$loopy=1;
while ($loopy<20)
{
if ($imagecat==$lo opy) {$batman=$loopy . ".php"; include($batman );}
$loopy=$loopy+1 ;
}

The above code is untested and really just intended to get you started .
<comp.lang.ph p>
<>
<Sun, 2 Dec 2007 15:44:12 -0800 (PST)>
<bd************ *************** *******@e4g2000 hsg.googlegroup s.com>
I am trying to generate an include name on an image gallery page from
a variable name.
By this I mean I already have a numeric value set the variable
$imageCat.

What I want to do is pull in an external include file using the
variable as the file name. So if $imageCat is set to 2 I want to bring
in 2.html ($imageCat.html ).

I can hard code each include request as such:

{if $imageCat=="2"}
{php}
include ("2.php");
{/php}
{/if}

But I am dealing with oodles of categories so this file would be huge.
A dynamic option would be very cool but I just can't seem to get my
syntax right.
Dec 3 '07 #2
at*******@yahoo .com wrote:
Hi

This may be simple to solve, but I can't seem to do it :(

I am trying to generate an include name on an image gallery page from
a variable name.
By this I mean I already have a numeric value set the variable
$imageCat.

What I want to do is pull in an external include file using the
variable as the file name. So if $imageCat is set to 2 I want to bring
in 2.html ($imageCat.html ).

I can hard code each include request as such:

{if $imageCat=="2"}
{php}
include ("2.php");
{/php}
{/if}

But I am dealing with oodles of categories so this file would be huge.
A dynamic option would be very cool but I just can't seem to get my
syntax right.

If anyone could give me even a vague pointer; I would be sooooo
greatful.

Many thanks

Mr M
I'm not sure what you're using, but {php} is not normal PHP syntax.

In PHP you could do something as easy as

include ($imageCat.'.'p hp');

But not knowing what you're using, I have no idea if it will work or not
for this.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Dec 3 '07 #3
Thanks for getting back to me.

It's just a regular php page I'm trying to do this with.

I couldn't get your suggestion below to work.

This works fine but still isn't dynamic:
include (include ("1.php");

It's been quite a while since I did any PHP so am pulling my hair out
about something that should be fairly straight forward.

Mr M

>
I'm not sure what you're using, but {php} is not normal PHP syntax.

In PHP you could do something as easy as

include ($imageCat.'.'p hp');

But not knowing what you're using, I have no idea if it will work or not
for this.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===
Dec 3 '07 #4
at*******@yahoo .com wrote:
>I'm not sure what you're using, but {php} is not normal PHP syntax.

In PHP you could do something as easy as

include ($imageCat.'.'p hp');

But not knowing what you're using, I have no idea if it will work or not
for this.
Thanks for getting back to me.

It's just a regular php page I'm trying to do this with.

I couldn't get your suggestion below to work.

This works fine but still isn't dynamic:
include (include ("1.php");

It's been quite a while since I did any PHP so am pulling my hair out
about something that should be fairly straight forward.

Mr M

(Top posting fixed)

This is not legal PHP code. Obviously you're using some templating
system, but you've never told us what you're using.

You really need to be asking these questions in the support group for
your templating system.

And please don't top post.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Dec 3 '07 #5
This looks like Smarty templating... if you're using Smarty, then the
code would be something like:

{if $imageCat=="2"}
{php}
$imageCat = $smarty->get_template_v ars('imageCat') ;
include ($imageCat . ".php");
{/php}
{/if}
Make sure you set the Smarty variable of $imageCat with
"$yourSmartyFor m->assign('imageC at','2');
On Dec 2, 5:44 pm, atwiaw...@yahoo .com wrote:
Hi

This may be simple to solve, but I can't seem to do it :(

I am trying to generate an include name on an image gallery page from
a variable name.
By this I mean I already have a numeric value set the variable
$imageCat.

What I want to do is pull in an external include file using the
variable as the file name. So if $imageCat is set to 2 I want to bring
in 2.html ($imageCat.html ).

I can hard code each include request as such:

{if $imageCat=="2"}
{php}
include ("2.php");
{/php}
{/if}

But I am dealing with oodles of categories so this file would be huge.
A dynamic option would be very cool but I just can't seem to get my
syntax right.

If anyone could give me even a vague pointer; I would be sooooo
greatful.

Many thanks

Mr M
Dec 3 '07 #6
Hi Acrobatic

Yes, I should have said earlier; it is smarty.

I understand the first bit, but the bit regarding "$yourSmartyFor m-
>assign('imageC at','2'); I'm a little lost with.
The code is for PHP Classifieds from DeltaScripts.

I'm getting nowhere on their forum and support system with this :(

Dec 4 '07 #7
I understand the first bit, but the bit regarding "$yourSmartyFor m-
assign('imageCa t','2'); I'm a little lost with.
In your code you need to assign a Smarty variable with the value of
the imageCat you want. Are you using Smarty forms, ie "$yourSmartyFor m
= new Smarty();"

If so, then you can assign a variable to be used in the {php} script
by saying $yourSmartyForm->assign('imageC at','2');

Then reference "$imageCat" within the {php} blocks. Clear as mud :)
Dec 4 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1888
by: Marcus | last post by:
Hello, I am having problems with an include statement. I'm setting a session variable flag and then including a file, and in that include file I have a check at the top to make sure that the session variable is set, otherwise I stop executing and redirect. My problem is that this works if I use a relative path to the include file, but not if I use the full path. If I use the full path, it does not read the session flag as being set,...
8
8338
by: Carolyn Speakman | last post by:
is it in any way possible to include a file specified by a variable name? Thanks, Carolyn
10
2540
by: Toke H?iland-J?rgensen | last post by:
Hello. I am quite new to the c++ language, and am still trying to learn it. I recently discovered how using include files would allow me to split up my code into smaller segments, instead of having class definitions etc. in one big file (yay, major discovery...). My problem is this: When I define a class in one include file, and then try to instantiate it in another, I get compile-time errors saying the type is invalid. If i move the...
6
2128
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file = ...\includes\StaffingHeaders.inc -->" </Script> <%=ClientName%> ****************************************************************************
3
5616
by: sunbeam | last post by:
Short Description of the Project: we developed a e-learning system for our students. each student has a unique username/password to view the modules he/she should view and nothing more. since we want to give them the opportunity to run these modules from home as well, we are trying to get the USERNAME/COMPUTERNAME as well, so the students, when they sign up for the modules, they can ONLY run the modules fromhome PC. We found a nice...
6
7598
by: Jordi | last post by:
I'm having a problem which I think has to do with the circular use of inlcuding header files. The short version of my code would look a bit like this, I think: GameEngine.h: #ifndef GAME_ENGINE #define GAME_ENGINE #include "Player.h" class GameEngine
6
4192
by: j.woodcock | last post by:
is there a way of having a file that's name is a variable (eg dependant on the user name) act like a include. i know that you cant define the file for an include asp tag using a variable and that reading the file using "Response.Write FSO.OpenTextFile(ppp, 1, False, False).readall" prints the file, and treating it like a html file. can anyone suggest another way of doing this?
3
2665
markmcgookin
by: markmcgookin | last post by:
Hi, I know this is a common issue, but to be honest all the sites I find with solutions to this dont explain it well at all. I have a variable ($fileName) which I want to add to http://tempuri.org/ then attach .xsd to the end
4
2229
by: rocketeer | last post by:
I've a set of Javascript classes that maintain state. For example, gm.js might be: var GroupManager { groups: {} }; Over time I add new groups to the list: GroupManager.groups = myGroup; If I include another Javascript file that also includes a reference to
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5403
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2897
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.