/    Sign up×
Community /Pin to ProfileBookmark

hmm, template and SQL

I have a template system that parses all tags like {HEAD} in the .tpl file.

I want to read all data from the db and add each one to a different variable.

I have tried stuff like:

[code=php]
$no = “1”;
while($row = mysql_fetch_array($result)){

$t.$no = “$row[‘text’]”;
$no++;
}

$titles = array(

‘T1’ => $t1,
‘T2’ => $t2,
‘T3’ => $t3,
‘T4’ => $t4,
‘T5’ => $t5,
‘T6’ => $t6,
‘T7’ => $t7,
‘T8’ => $t8,
‘T9’ => $t9,
‘T10’ => $t10,
‘T11’ => $t11,
‘T12’ => $t12,
‘T13’ => $t13,
‘T14’ => $t14,
‘T15’ => $t15
);
echo parse(‘index’,$titles);
?>
[/code]

But didnt work, I was wondering if I could do

[code=php]
$no = “1”;
while($row = mysql_fetch_array($result)){

$t1 = $row[“text[1]”];
……
$t15 = $row[“text[’15’]”];
}

$titles = array(

‘T1’ => $t1,
‘T2’ => $t2,
‘T3’ => $t3,
‘T4’ => $t4,
‘T5’ => $t5,
‘T6’ => $t6,
‘T7’ => $t7,
‘T8’ => $t8,
‘T9’ => $t9,
‘T10’ => $t10,
‘T11’ => $t11,
‘T12’ => $t12,
‘T13’ => $t13,
‘T14’ => $t14,
‘T15’ => $t15
);
echo parse(‘index’,$titles);
?>

[/code]

and maybe be able to use that without having to add all of them til 15. Could I use an array there like

[code=php]
$t[$no] $row[“text[$no]”];[/code]

Are there any other methods that are faster or use less bandwidth?

Aoeguy

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@aoeguyauthorJan 02.2004 — I dont understand the problem...

Here is the file (I changed that SQL bit again)

[code=php]<?PHP

include ('functions.php');
include ('/home/raider/sitedb.php');

Connect();

$query = "SELECT * FROM index_cat";
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){

$t1 = $row["text['1']"];
$t2 = $row["text['2']"];
}

$titles = array(

'T1' => $t1,
'T2' => $t2,
'T3' => $t3,
'T4' => $t4,
'T5' => $t5,
'T6' => $t6,
'T7' => $t7,
'T8' => $t8,
'T9' => $t9,
'T10' => $t10,
'T11' => $t11,
'T12' => $t12,
'T13' => $t13,
'T14' => $t14,
'T15' => $t15
);
echo parse('index',$titles);
?>[/code]


Please help
Copy linkTweet thisAlerts:
@pyroJan 02.2004 — Try it like this:

[code=php]while($row = mysql_fetch_array($result)){
$t.$no = $row['text'];
$no++;
}[/code]
Copy linkTweet thisAlerts:
@aoeguyauthorJan 03.2004 — I still get dumb Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/raider/public_html/template/index.php on line 11[/quote]

Thanks for that bit ?
Copy linkTweet thisAlerts:
@Sux0rZh_jc0rzJan 03.2004 — mayby u should show us the file so we can see whats wrong on line 11.. *falls asleep*
Copy linkTweet thisAlerts:
@pyroJan 03.2004 — Yes, that would be very helpful. You probably have an error in your SQL statement.
Copy linkTweet thisAlerts:
@aoeguyauthorJan 04.2004 — Its the array bit, well here is the contents:

[code=php]<?PHP

include ('functions.php');
include ('/home/raider/sitedb.php');

Connect();

$no = "1";
$query = "SELECT * FROM index_cat";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){

$t.$no = $row['text'];
$no++;
}

$titles = array(

'T1' => $t1,
'T2' => $t2,
'T3' => $t3,
'T4' => $t4,
'T5' => $t5,
'T6' => $t6,
'T7' => $t7,
'T8' => $t8,
'T9' => $t9,
'T10' => $t10,
'T11' => $t11,
'T12' => $t12,
'T13' => $t13,
'T14' => $t14,
'T15' => $t15
);
echo parse('index',$titles);
?>[/code]
×

Success!

Help @aoeguy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...