473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Help with using a loop to pull data from mysql recordset

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
pages.

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'); ?>
<?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
Nov 22 '05 #1
3 6374
Following on from Jim Hernandez's message. . .
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.
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.

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 .
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Nov 22 '05 #2
Jim Hernandez wrote:
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
pages.

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'); ?>
<?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

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.
js*******@attglobal.net
==================
Nov 22 '05 #3
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
".$databasename);

//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
".$query_byartist);

//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
$row["areviews.atitle"]
}

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

mysql_free_result($result);
mysql_close($link);

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

Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Phil Powell | last post by:
I've read some online resources that utilize various MySQL command-line actions to migrate data from Access to MySQL. The situation is this: a group of co-workers of mine will be using an Access...
7
by: Munzilla | last post by:
Ok, I have an ASP page that I use to add several pieces of information to a database and also display that information in an edit mode. The problem is, when I use the page for edit, not all of the...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
9
by: tym | last post by:
HELP!!! I'm going round the twist with this... I have a VB6 application which is using DAO to access a database (Please - no lectures on ADO, I know what I'm doing with DAO!!) Ok, problem...
4
by: Mark | last post by:
the Following bit of code doesn't work. It seems to respond to the second, starting with 'add iif statement for Good Practice', but not to the first, starting 'add iif statement for archived' ...
7
by: Dave Hopper | last post by:
Hi I posted a question recently regarding problems I am having getting a value from a list box to use in a query. I got a lot of help, for which I thank you and it's nearly working! But I need...
31
by: Extremest | last post by:
I have a loop that is set to run as long as the arraylist is > 0. at the beginning of this loop I grab the first object and then remove it. I then go into another loop that checks to see if there...
2
by: Extremest | last post by:
Here is the code I have so far. It connects to a db and grabs headers. It then sorts them into groups and then puts all the complete ones into another table. Problem I am having is that for some...
1
by: terryspanky | last post by:
----------------------Below are all the codes don't have errors---- The only problem I have is when I Delete, I'ts not deleting the subject that I click. I want to use the above codes to modify the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.