Page 1 of 1

how do I list diferent fields from same query

Posted: Fri Jul 12, 2002 9:46 am
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?

Posted: Fri Jul 12, 2002 11:28 am
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.

Posted: Fri Jul 12, 2002 12:26 pm
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?

Database Normalization

Posted: Fri Jul 12, 2002 1:02 pm
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.

thanks

Posted: Fri Jul 12, 2002 2:10 pm
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.