how do I list diferent fields from same query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
godfrey
Forum Newbie
Posts: 7
Joined: Fri Jul 12, 2002 9:46 am
Contact:

how do I list diferent fields from same query

Post by godfrey »

hope the title is clear, english is not my first language.

I have a database with all my CDs so what I want to do is list the CD titles, and songs of each in one table and in another table make a link to the coresponding songbook

the following works fine

<?php while($categorydb->next_record()): ?>
<li><a href="<?echo $categorydb->Record["id"];?>/<? echo $categorydb->Record["id"] ?>.htm">
<B><? echo $categorydb->Record["categoria"] ?></B>
<?php endwhile ?>

but then it gives an error on the second part


<?php while($categorydb->next_record()): ?>
<b><? echo $categorydb->Record["categoria"] ?></B>
<?
$currentcategory = $categorydb->Record["id"];
$seriedb = new Sample;
$seriequery = "select * from cd_titulos where catid = $currentcategory order by sid";
$seriedb->query($seriequery);
?>
<ul>
<?php while($seriedb->next_record()): ?>
<li>
<a href="<?echo $seriedb->Record["catid"];?>/<? echo $seriedb->Record["sid"] ?>.zip"><? echo $seriedb->Record["alt_text"];
?></a></li><br>
<?php endwhile ?>
</ul></font></p>


unless I do not end while after the first part, but then it also loops through all the htm code which is inbetween which I do not want.

any suggestion what I can do?
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

You can start with the fact that you have 3 while statement and only 2 endwhile statements. Maybe one just got cut off; I don't know. I don't have much experience with PHP classes.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

$categorydb->next_record() what does this do

Is it iterating through an array, if so after the first while loop have you reset the array back to the start? Is it accessing a database query in your class, if so when is the query called, must be before you call the next_record() function, right?
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Database Normalization

Post by EricS »

I would think about restructuring the database to make it faster.

I would have one table with just the CD Title and a unique key and then another table with the songs, and the unique key pointing back to the title cd it came from.

This will save disk space and speed up queries when the database gets large.

Just my opinion.
godfrey
Forum Newbie
Posts: 7
Joined: Fri Jul 12, 2002 9:46 am
Contact:

thanks

Post by godfrey »

thank you so much, I think it has todo with having to reset the query. I'll be playing aroung with it some more. Thanks for all your replys.
Post Reply