![]() |
What way could I do this
I was just wondering I have all of these arrays such as $user[name]; Now what my problem is I have a repeating loop that gets a few templates that I store in the database. Don't ask why I just want them their for what I'm trying to learn. My problem is whenever I loop and echo, some of those templates will call upon stuff like $user[name] and it should output a text of like Joe for example... instead it only ouputs the actual text of $user[name].
Hopefully I'm not confusing anyone, but is there a way that if you define something in a file and then run a query if the query has any information on the echo statement of whats stored inside such as an array or variable that on the output it would display what it has been defined too? |
You muste evaluate templates to get the variables in:
PHP Code:
|
Look at the code at the top of every vB file, see a pattern? Especially this...
PHP Code:
yeah, and what he said too. |
So lets say I had something like this...
PHP Code:
|
PHP Code:
|
There's a few problems that arise when I do that... It now retrieves the data but at the same time when it does, it now won't let me do like set widths for tables or to be able to call upon any CSS such as the class = to whatever and so forth... Any ways around that one?
|
Hmm ...
PHP Code:
HTML Code:
<table width="100%" class="mytable"><tr><td>Foo Bar</td></tr></table> |
I've triple checked this and something is definately wrong with this... This is my entire php code for anything retaining towards the templates.
PHP Code:
|
The code seems to be OK.
Can you post a template that does not work? |
PHP Code:
|
Try this
PHP Code:
|
Quote:
in HTML all attribute varibles should be nested inside of DOUBLE quotes, not SINGLE HTML Code:
<body bgcolor="#ffffff" leftmargin="0" topmargin="0" bottommargin="0" rightmargin="0"> |
Hmmm I figured if I used " then php could get an error... guess not. My last question is now for my news I want to display a loop statement, which I use a while. Now I know this won't work correctly because I'm using a mysql_fetch_array query inside a while statement and it is going to loop the number of times I have an entree in the db. So how exactly could I take a while statement that is going to loop and actually store the information in the template so it shows each and every loop, such as $news[news_name] should loop 8 times and thus loops 8 times in the template and shoes each array being different then the last?
|
I've read this 3 times now and still don't understand your problem :(
|
Quote:
Quote:
|
LoL sorry, I know you'll understand it this way.
PHP Code:
|
I don't understand what you want, but I guess you want this:
PHP Code:
|
Nah I don't think your following me. You have a while { }. Let's say it loops 5 times and the following pieces of data it is going to pull from the same table in the database becaused you used a get array query.
John Joe Jerry James Judy It retrieves 5 names. And in order to retrieve those 5 names all I had to type inside the while brackets were something like $news[display_names]. That is it. Well on the template how could I get it so that it displays all 5 loops so each name is displayed because I can't write the php statement inside the template, nor can I output the echo statement inside the while loop. I know vBulletin does this when it wants to ouput like each forum's description, name, and so forth on their forumhome but vb uses a lot more coding that is far too advanced and complex for my simple brain. Any ideas? |
So in simple words:
You want the news_name values from all rows in the table in one string? Before the while: PHP Code:
PHP Code:
PHP Code:
|
The implode function works... but not exactly as needed. I'm trying to retrieve 3 specific bits of information. news_name, news_id, news_description. When i use the implode function I can only assign one variable and have it implode one bit of information. To make it easier to understand this is what I want it to look like when complete for the output.
<tr> <td>$news_name</td><td>$news_id</td><td>$news_description</td> </tr> So it'd display the following bits of info on the output Joe 1 This is my piece of writing John 2 I don't like writing Jerry 3 Wow I can't believe I did this Jose 4 WEEEE! Currently it'll display JoeJohnjerryJose 1234 ect. Basically I want to use a little simple html to seperate everything a bit and for me to only have to call upon a few variables in my templates in order to complete this process. With the implode function I can't necessarily do that because if I call upon something like $news_name it will loop all the $news_names that I have selected. And thus on the output will look horribly ugly. Is there any function i can use so I could like insert this html and it'd select those 3... then loop again and keep looping like the implode function did until the while statement is over? |
Are we getting there? ^.^
Save this as template newsbit Code:
<tr> PHP Code:
PHP Code:
|
How can I evaluate a variable from an array (not using while...fetch_array because there is no SQL involved)?
PHP Code:
|
foreach instead of a while maybe.
|
All times are GMT. The time now is 04:50 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:
|