|
-
Mar 12th, 2003, 08:18 PM
#1
Thread Starter
Hyperactive Member
Loop through database...
Ok im back again and i am still trying to loop through my database in a template. is this how i would loop through it? i need to loop through the ID of the item first then while its still doing that print out the data?
so
loop {
$dbid
loop {
$dbtext
}
}
or something like that? do you think you could help me put this in php?
-
Mar 12th, 2003, 09:28 PM
#2
Frenzied Member
loop through the id first?? huh you can't do that.
just loop through the whole table do this
PHP Code:
$query=("select * from table")
while ($row= musql_fetch_array($query){
echo $row["id"];
echo $row["field1"];
}
that will loop through the whole db and display every ID and FIELD1
so what are you having trouble with? you said a template?
-
Mar 13th, 2003, 03:35 PM
#3
Thread Starter
Hyperactive Member
well im trying to use a template engine like fasttemplate so i can have someone do the html and stuff and i just work on the php part. but whenever i do it, it only displayes one item from the database.
-
Mar 13th, 2003, 03:49 PM
#4
Stuck in the 80s
Originally posted by Muk108
well im trying to use a template engine like fasttemplate so i can have someone do the html and stuff and i just work on the php part. but whenever i do it, it only displayes one item from the database.
You'd probably have to post your code before we can find the bug...
-
Mar 13th, 2003, 05:01 PM
#5
Thread Starter
Hyperactive Member
PHP Code:
<?
include("db.php");
include("class.FastTemplate.php3");
if ($complete != 1)
$news = mysql_query($query);
while ($row = mysql_fetch_array($news)) {
$title_text = $row['main_title'];
};
//
$menu = "SELECT * FROM menu_left ORDER BY menu_order";
if ($complete != 1)
$menu_left = mysql_query($menu);
while ($menurow == mysql_fetch_array($menu_left)) {
if ($menurow['menu_show'] == 1) {
$menu_link[] = $menurow['menu_link'];
$menu_name[] = $menurow['menu_name'];
} else {
echo "";
};
}
//
$newsquery = "SELECT * FROM news";
if ($complete != 1)
$news = mysql_query($newsquery);
while ($row = mysql_fetch_array($news)) {
$news_title_text = $row['news_title'];
$news_message_text = $row['news_message'];
$news_submitter_text = $row['news_submitter'];
$news_date_text = $row['news_date'];
};
//
$tpl = new FastTemplate("./templates");
$tpl->define(array(
'main' => "index.tpl",
)
);
//
$tpl->assign(
array(
'title' => $title_text,
'news_title_text' => $news_title_text,
'news_message_text' => $news_message_text,
'news_submitter_text' => $news_submitter_text,
'news_date_text' => $news_date_text,
'menu_link' => $menu_link,
'menu_name' => $menu_name,
'message_area' => $message_area,)
);
$tpl->parse('MAIN', array("main"));
$tpl->FastPrint();
//$tpl->showDebugInfo();
exit;
?>
thats what i have, i have been working with this for a long time, hope you can help me.
-
Mar 13th, 2003, 05:44 PM
#6
Frenzied Member
is this it?
PHP Code:
while ($row = mysql_fetch_array($news)) {
$news_title_text = $row['news_title'];
$news_message_text = $row['news_message'];
$news_submitter_text = $row['news_submitter'];
$news_date_text = $row['news_date'];
};
that will only get the last info from teh db, so the last id will only be sent. I thought we fixed this a while ago.
-
Mar 13th, 2003, 05:46 PM
#7
Thread Starter
Hyperactive Member
no, i dont think we did, or we did and when i tryed putting it in it didnt work. could you help me with this one?
-
Mar 13th, 2003, 06:26 PM
#8
Stuck in the 80s
This is a problem right here:
Code:
while ($menurow == mysql_fetch_array($menu_left)) {
Should only be one = sign.
-
Mar 13th, 2003, 06:37 PM
#9
Thread Starter
Hyperactive Member
that doesnt seem to matter, i still only get one resault printed out on the page.
-
Mar 13th, 2003, 10:03 PM
#10
Stuck in the 80s
Originally posted by Muk108
that doesnt seem to matter, i still only get one resault printed out on the page.
It may not fix your problem, but yes, it does matter, as that's not how you do it.
-
Mar 13th, 2003, 10:20 PM
#11
Thread Starter
Hyperactive Member
ok well, thank you. i have tryed a for loop at
PHP Code:
$tpl->assign(
array(
'title' => $title_text,
'news_title_text' => $news_title_text,
'news_message_text' => $news_message_text,
'news_submitter_text' => $news_submitter_text,
'news_date_text' => $news_date_text,
'menu_link' => $menu_link,
'menu_name' => $menu_name,
'message_area' => $message_area,)
);
this point. but still no luck.
-
Mar 13th, 2003, 10:41 PM
#12
Stuck in the 80s
I think phpman hit the nail on the head. You need to do something like this:
Code:
<?php
include("db.php");
include("class.FastTemplate.php3");
if ($complete != 1)
$news = mysql_query($query);
while ($row = mysql_fetch_array($news)) {
$title_text[] = $row['main_title'];
}
//
$menu = "SELECT * FROM menu_left ORDER BY menu_order";
if ($complete != 1)
$menu_left = mysql_query($menu);
while ($menurow == mysql_fetch_array($menu_left)) {
if ($menurow['menu_show'] == 1) {
$menu_link[] = $menurow['menu_link'];
$menu_name[] = $menurow['menu_name'];
} else {
echo "";
}
}
$newsquery = "SELECT * FROM news";
if ($complete != 1)
$news = mysql_query($newsquery);
while ($row = mysql_fetch_array($news)) {
$news_title_text[] = $row['news_title'];
$news_message_text[] = $row['news_message'];
$news_submitter_text[] = $row['news_submitter'];
$news_date_text[] = $row['news_date'];
}
$tpl = new FastTemplate("./templates");
$tpl->define(array('main' => "index.tpl",));
// ^-- what's that comma doing in there?
for ($i = 0; $i < count($title_text); $i++) {
$tpl->assign(
array(
'title' => $title_text[$i],
'news_title_text' => $news_title_text[$i],
'news_message_text' => $news_message_text[$i],
'news_submitter_text' => $news_submitter_text[$i],
'news_date_text' => $news_date_text[$i],
'menu_link' => $menu_link[$i],
'menu_name' => $menu_name[$i],
'message_area' => $message_area[$i],)
//^--what's up with that last comma?
);
$tpl->parse('MAIN', array("main"));
$tpl->FastPrint();
//$tpl->showDebugInfo();
}
exit;
?>
Give it a try. I believe it will work
-
Mar 14th, 2003, 12:31 AM
#13
Frenzied Member
exactly, Hobo.
see that is what you needed to do, Muk108. jsu tlike this thread where you just left it hanging
http://www.vbforums.com/showthread.p...hreadid=228334
you never said it didn't work and we told you what the problem was. and again you ask the same question and got the same answer.
-
Mar 14th, 2003, 08:18 AM
#14
Stuck in the 80s
Originally posted by phpman
see that is what you needed to do, Muk108. jsu tlike this thread where you just left it hanging
http://www.vbforums.com/showthread.p...hreadid=228334
you never said it didn't work and we told you what the problem was. and again you ask the same question and got the same answer.
I guess when you don't like the answer, you can ask again later and see if you get a different one.
Sadly, for him, this is the answer.
-
Mar 15th, 2003, 09:07 PM
#15
Thread Starter
Hyperactive Member
im sorry i havent replyed, i was buisy the last two days. and when i execute that i go this error....
Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\HTTP\www\intra\index.php on line 71
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\HTTP\www\intra\index.php on line 81
and it just loops through that locking up my server.
-
Mar 15th, 2003, 09:23 PM
#16
Thread Starter
Hyperactive Member
ok i got the page to load, but now for ME, it doesnt want to loop through and print it out again...
-
Mar 17th, 2003, 06:54 PM
#17
Stuck in the 80s
Originally posted by Muk108
ok i got the page to load, but now for ME, it doesnt want to loop through and print it out again...
I don't know what to tell you anymore. Try finding some basic tutorials first. Or maybe programming concepts.
Not to overuse a cliche, but we can only lead you to water...
-
Mar 17th, 2003, 08:38 PM
#18
Thread Starter
Hyperactive Member
i understand i have been looking at tutorials and havnt found anything. ill keep looking and when i find it ill post it. thanks for all your guys help.
-
Mar 17th, 2003, 10:40 PM
#19
Frenzied Member
my guess is that you messed up the query when you got the mysql_fetch_arrary errors.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|