473,791 Members | 3,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select/Join query help (dropdown box?)

Hey everyone.

I'm re-writing a php Content Management System (based loosely on
phpNuke but specific to my site). My first major change was attempting
to normalise the Review section database structure. I've created a
Staff table with staff email addresses and names (plus id), and a
Reviews table with the text of the reviews. The Reviews table contains
an 'author' field with a value that corresponds to the Staff table.
When I display a review, I successfully used an Inner Join to link the
records and display the correct author name/email for the relevant
review.

My problem now is when editing the reviews. I originally had a basic
php page that simply selected the values and loaded them into a form,
but I can't get this to work now. Specifically, In the Submit form for
Reviews, I created a dropdown box which loaded the values from the
Staff table. When storing a review, it correctly stores the value for
the selected Author's ID in the Review table. My problem is when
editing the review, I cannot get php to lookup the author ID in the
Reviews table, then display in the dropdown the correct Author Name
from the Staff table for that specific review.

Could anyone help? The MySQL manual for joins may as well be written in
Greek.

Matt

Jul 17 '05
17 2638
I'm sorry, I didn't follow. What did you mean by:

"Let's assume you have defined a variable $Staff_id_db from your first
query"?

Jul 17 '05 #11
I noticed that Message-ID:
<11************ **********@f14g 2000cwb.googleg roups.com> from
gu************@ gmail.com contained the following:
I'm sorry, I didn't follow. What did you mean by:

"Let's assume you have defined a variable $Staff_id_db from your first
query"?


Your first query:

$query = "SELECT Band_Name, Record_Name, Review, Staff_Name, Staff_id,
Score, Cover_Image, Record_Label, Band_Site_URL
FROM review_test INNER JOIN staff ON Reviewer_Name = staff.Staff_id
WHERE id='$id'";
$result = mysql_query($qu ery) or die('Error : ' . mysql_error());

if you do:
$myrow=mysql_fe tch assoc($result);

then $myrow['Staff_id'] will contain the staff id of the person who
wrote the review, no?

Compare that with the results from the query of the staff table to
determine which should be selected in the select box

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #12
Sorry to be a constant pain; I'm really doing my best to understand
this, but it's a hot day.. etc. I still can't get this to work; all the
following code is doing is selecting the final value in the dropdown
instead.

This is what I have:

echo "<select name=\"Reviewer _Name\" id=\"Reviewer_N ame\"
value=\"Staff_i d\">";

$myrow="mysql_f etch assoc($mattresu lt)";

while($row3 = mysql_fetch_arr ay($result2, MYSQL_NUM))
{
list($Staff_id, $Staff_Name) = $row3;

//check if this option should be selected
if($Staff_id==$ myrow['Staff_id']){
$selected="sele cted";
}
else{
$selected="";
}
echo "<option value=\"$Staff_ id\"
selected=\"$sel ected\">$Staff_ Name</option>";
}
echo "</select>";

$mattresult is the result of the query you just posted.
$result2 is the second query that looks up all the values in the staff
table.

Jul 17 '05 #13
I noticed that Message-ID:
<11************ **********@o13g 2000cwo.googleg roups.com> from
gu************@ gmail.com contained the following:

Echo these variables to the screen to see if you are getting what you
think you are getting
if($Staff_id==$ myrow['Staff_id']){
$selected="sele cted";
}
else{
$selected="";
}
echo "<option value=\"$Staff_ id\"
selected=\"$se lected\">$Staff _Name</option>";


Incorrect html. It should be

echo "<option value=\"$Staff_ id\"$selected>$ Staff_Name</option>";

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #14
Okay, $myrow['Staff_id'] is returning 'm'. Uh..

As for $Staff_id, it is now displaying the same value (46) no matter
what review I display (which obviously have different authors).

As for the html, I just (wrongly?) presumed that the if statement would
simply input the text 'selected' into the code, so I thought making the
attribute="$sel ected" was the proper way to achieve this.

Jul 17 '05 #15
I noticed that Message-ID:
<11************ *********@g43g2 000cwa.googlegr oups.com> from
gu************@ gmail.com contained the following:
Okay, $myrow['Staff_id'] is returning 'm'. Uh..
Then that's what it contains <shrug> Have you checked the data?
As for $Staff_id, it is now displaying the same value (46) no matter
what review I display (which obviously have different authors).
So it should. $Staff_id is coming from your query of all reviewers and
changes each time you go round the loop. I assume you are echoing it
when the loop ends
As for the html, I just (wrongly?) presumed that the if statement would
simply input the text 'selected' into the code, so I thought making the
attribute="$se lected" was the proper way to achieve this.


Nope. :-)

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #16
Argh, I give up. The value for $Staff_id is definitely NOT m, anywhere.
The ID field is a auto_incrementi ng primary key, so that doesn't make
sense. I have the page looking up the reviewer entered, I just can't
let the editor (easily) modify the reviewer. I guess I'll just put a
message on the page saying to make sure they select the right reviewer
when posting.

Jul 17 '05 #17
I noticed that Message-ID:
<11************ **********@g49g 2000cwa.googleg roups.com> from
gu************@ gmail.com contained the following:
Argh, I give up. The value for $Staff_id is definitely NOT m, anywhere.
The ID field is a auto_incrementi ng primary key, so that doesn't make
sense. I have the page looking up the reviewer entered, I just can't
let the editor (easily) modify the reviewer. I guess I'll just put a
message on the page saying to make sure they select the right reviewer
when posting.


In that case why do they need to edit the reviewer at all? Just echo
the name of the reviewer to the screen and leave it out of the update
query so it is not changed.

I think you need to look carefully at where your variables are coming
from.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #18

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

Similar topics

3
2291
by: jagg | last post by:
Hi, i save junior football results in a mysql table (FIELDS id jugend autor sptag ergebnis spdatum zeit ) With the following lines I generate a site whichs gives me ALL results Code: <table border="0" cellspacing="1" cellpadding="2" class="content" width="100%">
3
3548
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
4
2866
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table that links to a transaction items table that links to the products table: (User Table) UserID Other user data
3
6472
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
1
4179
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
4
10326
by: Ben | last post by:
I believe I am missunderstanding how subqueries work. I simple subquery works fine but when I wish do compare 2 or more fields at once I don't get the results I wish. Table A ID First Last Other 1 A Z 1 2 B Y 2 3 C Z 3
0
1919
by: Susan Bricker | last post by:
The following error: "The current field must match the join key '?' in the table that seves as t the 'one' side of one-to-many relationship. Enter a record in the 'one' side table with the desired key value, and then make the entry with the desired join key in the 'many-only' table." ... happens when I click on an entry of a combobox. HELP!! Here's the background:
0
2234
by: rayone | last post by:
Hi folks. I need advice. 2 options, which do you think is the better option to display/retrieve/report on the data. Keep in mind reporting (Crystal), SQL Performance, VB Code, usability, architecture. Case 1: On a web page I would like to render a dropdown list
0
1287
kcdoell
by: kcdoell | last post by:
Hello: I have a form that I am using to help me display a query that I have built. On that form I have multiple combo boxes that I have called cobMonth, cobYear, cobWorkingRegion, etc... (basically these are certain field names in my query). I also have a command button called “Run query”. Currently, I have designed it so that if I select any of the options in my dropdown list I am able to narrow down my query result. I accomplished this by...
0
9669
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.