473,387 Members | 1,760 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,387 software developers and data experts.

How to use result from one query as criteria in a second query

Ok, I took a whack at this, but it's still not returning anything.
Granted I used Dreamweaver to create the queries, but I must be messed
up somewhere.

Any help would be appreciated.
1st Query: (this ones works wonderfully)
mysql_select_db($database_db********, $db********);
$query_new_review_one = "SELECT Artists.Artist,
tbl_reviews.album_title, tbl_reviews.opener, tbl_reviews.score,
Albums.image_location, tbl_reviews.artist_id FROM tbl_reviews,
Artists, Albums WHERE tbl_reviews.artist_id = Artists.ID AND
Albums.Album_Name =tbl_reviews.album_title ORDER BY review_id DESC
LIMIT 1";
$new_review_one = mysql_query($query_new_review_one, $db99532137) or
die(mysql_error());
$row_new_review_one = mysql_fetch_assoc($new_review_one);
$totalRows_new_review_one = mysql_num_rows($new_review_one);
Variable Set and Second Query:
$album_user_review_one = "1";
if (isset($row_new_review_one['album_title'])) {
$album_user_review_one = (get_magic_quotes_gpc()) ?
$row_new_review_one['album_title'] :
addslashes($row_new_review_one['album_title']);
}

mysql_select_db($database_db********, $db********);
$query_user_review_one = sprintf("SELECT AVG(tbl_user_reviews.score)
FROM tbl_user_reviews WHERE tbl_user_reviews.album_title = '%s'",
$album_user_review_one);
$user_review_one = mysql_query($query_user_review_one, $db99532137) or
die(mysql_error());
$row_user_review_one = mysql_fetch_assoc($user_review_one);
$totalRows_user_review_one = mysql_num_rows($user_review_one);
Jul 20 '05 #1
1 1377
Don Seckler wrote:
$album_user_review_one = "1";
if (isset($row_new_review_one['album_title'])) {
$album_user_review_one = (get_magic_quotes_gpc()) ?
$row_new_review_one['album_title'] :
addslashes($row_new_review_one['album_title']);
There's also a function mysql_escape_string(), which probably does a
similar thing as addslashes(), but the former is intended for MySQL.
Perhaps there's some case of special characters needed for MySQL, but
which addslashes() is not covering.
}

mysql_select_db($database_db********, $db********);
$query_user_review_one = sprintf("SELECT AVG(tbl_user_reviews.score)
FROM tbl_user_reviews WHERE tbl_user_reviews.album_title = '%s'",
$album_user_review_one);
The usual advice in this kind of situation is that you should print the
resulting SQL string to some diagnostic output before executing it. The
error is much easier to spot that way. Whenever you construct SQL
programmatically, no matter how simple it seems to be, sometimes it
doesn't turn out as you expect.

It seems to me that there is at least one case in which
$album_user_review_one could be "1".
$user_review_one = mysql_query($query_user_review_one, $db99532137) or
die(mysql_error());
$row_user_review_one = mysql_fetch_assoc($user_review_one);
$totalRows_user_review_one = mysql_num_rows($user_review_one);


Regards,
Bill K.
Jul 20 '05 #2

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

Similar topics

3
by: Steve | last post by:
Form FrmRestock's recordsource is QryFrmRestock. The TransactionDate field's criteria is set ats: Forms!FrmRestock!LastXDays. LastXDays on the form is a combobox where the selections are 30, 60...
4
by: nick_faye | last post by:
hi, hope someone can help me. i am a newbie in creating queries and i want to create a query wherein i only get entries from my table where values of fields 2, 3 and 4 are not zeros. for...
6
by: Liz Malcolm | last post by:
Hello and Thanks in advance for any help. I am using Access 2000. I have a data entry form that opens a main form (using the On Click event of the combo box ) with tab controls and 1 subform on...
2
by: Matthew | last post by:
Hey , I have built a query which takes values from unbounded fields on a form, and it all works except for one thing. I have a few fields in my query that are dates. I also have a start and...
3
by: hmiller | last post by:
Hey everyone, I am having a hell of a time trying to set this menu system up. Here's what I'm trying to do. Combo Box One; is populated by names under properties "row source" "Phase 1"...
7
by: keliie | last post by:
Hello Just a quick question that I've spent a few hours trying to solve with no luck (although one would think this should be fairly easy). I have a form with a subform. The subform is based...
5
by: DeanL | last post by:
Hi all, I'm trying to set up a query that runs from a command button on a form (simple enough so far), what I want the query to do is take values from the fields on the form (seven fields in...
1
by: Maarten van der Cammen | last post by:
Hi, In a table I have two numeric fields (e.g. FieldA and FieldB). Both fields have double precicion (field size "double"), Format "Fixed" and Decimal places "3" since I want to calculate with...
6
by: Vince | last post by:
Hello all, I am using Visual Basic to open a saved query and then save information in the query to an array for later use. The problem is that the same query shows different results when opened...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.