Help with using a loop to pull data from mysql recordset

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
This has set me back a couple of days  now and I could really use some  
help or at least a shove in the right direction.

What  I'm trying to do is list reviews in a database on a page, by  
artist (byartist.php).  The first step is pulling each artist and  
listing them alphabetically.  If the artist has more than one album  
reviewed, they should still only show up once, so I need to check each  
row of the recordset, and check the artistname against a variable or  
something, and if it exists, to just skip it and move on to the next row.
Then I need to list the albums reviewed under each respective artists  
name and use them as links with url parameters to the respective review  

I've got the recordset down per some advice from another newsgroup, and  
I'm fairly certain its correct for what I need to do.
<?php require_once('conntest.php'); ?>
mysql_select_db($database_test, $test);
$query_byartist = "select artists.artistid, artists.artistname,  
areviews.albumid, areviews.atitle from artists join areviews on  
artists.artistid = areviews.artistid";
$byartist = mysql_query($query_byartist, $test) or die(mysql_error());
$row_byartist = mysql_fetch_assoc($byartist);
$totalRows_byartist = mysql_num_rows($byartist);

The php example I was given for pulling the results was kind of  
half-effort and not enough for me to really see what was going on,  
understand it and build upon it.  I'm (obviously) just starting out with  
php/mysql and I'm pretty good at building upon something in front of me  
and figuring it out, just need a little help because I've tried it over  
and over and to no avail, I wind up with syntax errors.
Sorry for the wordy post, I didnt want to skimp.  Thanks for any help or  
advice or any points in the right direction.  I've got about 3 days of  
progress to catch up on

Re: Help with using a loop to pull data from mysql recordset

Following on from Jim Hernandez's message. . .
Quoted text here. Click to load it

The story in your post contradicts the assertion that you are good at  
adapting things.  It may be tedious to RTFM, and you may still need to  
experiment and refine, but experimenting and refining will be a great  
deal quicker.

PETER FOX Not the same since the e-commerce business came to a .
2 Tees Close, Witham, Essex.
Gravity beer in Essex  <

Re: Help with using a loop to pull data from mysql recordset

Jim Hernandez wrote:
Quoted text here. Click to load it

OK, looks like you're off to a decent start.  You're splitting the  
albums and reviews into separate tables, which is good.

So exactly what have you tried which causes the syntax errors?  What is  
the exact message you're getting?

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Help with using a loop to pull data from mysql recordset

It would be cool if you could post a few more details, especially of
the errors you're getting.  What I gather from your post is that you
are having difficulties getting data out of the db and you're not
confident about how your example worked so here's an annotated typical
sample query

//first you connect and select the db
$link = mysql_connect($mysqlserverip, $mysqlusername, $mysqlpassword)
or die("Could not connect");
mysql_select_db($databasename, $link) or die("Could not select

//then perform your query (your query looked OK xcept you may need to
areviews.artistid in the first list)
$result = mysql_query($query_byartist, $link) or die("Query failed

//now you've got a result set you need to got thru each result.  they
way this works can seem a little strange at first.  each call to
mysql_fetch_assoc (or mysql_fetch_array etc.) returns the next result
if available or false otherwise

while ($row = mysql_fetch_assoc($result))
    //now you have an array $row where the each item in the array
represents a field in the db record.  For example, to print out the
title of the review you would write

  echo $row["atitle"];

  //Note that only the field name is used in the index (as opposed to

//finally you should free up all the resources used.  Obviously none of
us ever forget this ;-)


Hope i've interpreted your problem correctly and that this helps you
work it out.

Site Timeline