473,799 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mysql_fetch_arr ay and multitable queries

I have a query that looks at two tables and pulls all the data back:

SELECT * FROM venues, status WHERE status_id = fk_status_id

I then have a class to hold the information I want. To initialise it I
get the data from the results set as per normal. The issue I have is
that two fields have the field name 'name'. In SQL terms I would refer
to them like 'tablename.colu mnname'. How do I achieve this using a
mysql fetch array?

The code I am using below brings back empty/null items for the
'tablename.colu mnname'.

$row = mysql_fetch_arr ay( $rs );
$vn = new venue();
$vn->params_init( $row['venue_id'],
$row['venues.name'], /*HERE*/
$row['address1'],
$row['address2'],
$row['address3'],
$row['town_city'],
$row['county'],
$row['postcode'],
$row['other_details'],
$row['url'],
$row['status.name'], /*HERE */
$row['copy_of_id']
);

In this instance I am developing the database so I can get round it by
changing the field names, but in the future I may not be able to.

If possible I want to avoid using two queries to get the information I
require.

Regards,

Rick Huby
www.e-connected.com

Oct 13 '05 #1
3 1644

"thehuby" <th*****@gmail. com> schreef in bericht
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I have a query that looks at two tables and pulls all the data back:

SELECT * FROM venues, status WHERE status_id = fk_status_id

I then have a class to hold the information I want. To initialise it I
get the data from the results set as per normal. The issue I have is
that two fields have the field name 'name'. In SQL terms I would refer
to them like 'tablename.colu mnname'. How do I achieve this using a
mysql fetch array?


$SQL = "SELECT tablename.colum nname AS name1,tablename 2.columnname AS name2
FROM ............";

$RESULT = mysql_query($SQ L);

$RECORD = mysql_fetch_arr ay($RESULT)

$name1 = $RECORD['name1'];
$name2 = $RECORD['name2'];
Oct 13 '05 #2
select * is fairly dangerous -- only because you don't know what you
are (or aren't getting). If you explicitly list out your columns you
can alias them and get to them that way:

SELECT v.venue_id,
v.name venue_name,
v.address1,
...
v.url,
s.name status_name
FROM venues v, status s
WHERE s.status_id = v.fk_status_id

Here I called venue.name venue_name and status.name status_name. So in
your row, you can do $row['venue_name'] and $row['status_name'].

Oct 13 '05 #3
Thank you both very much - that really helps me.

Regards,

Rick

Oct 13 '05 #4

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

Similar topics

5
2029
by: james | last post by:
I am new to PHP and am trying to run a simple query and display the result, with no luck. Here is the code I am using. <?php //start session session_start(); //store cmpid from querystring $_SESSION = $_GET;
4
7022
by: Theo | last post by:
hi all this is probably another simple one, but the web doesnt seem to have an answer that I can find. Veeeery simple code. each row has 10 columns. require('db.php'); $query = "SELECT * FROM mytable";
15
2689
by: Good Man | last post by:
Hey there I have a dumb question.... Let's say i have a database full of 4000 people.... I select everything from the database by: $result = mysql_query("SELECT * FROM People");
2
6107
by: Dave Moore | last post by:
Hi All, I've got a simple query hopefully somebody can clear up for me. I need to make a query on a database to select a set of table rows, using something like: $result = mysql_query($query); I can then use mysql_fetch_array in a while loop to access each row in the result. This all works fine.
4
2967
by: Marcel Brekelmans | last post by:
Hello, I seem to get an extra empty field in every 'mysql_fetch_array' command I issue. For example: I have a simple table 'tblName': ID Name 1 Jane 2 Joe 2 Doe
2
15909
by: alexbarham | last post by:
I am working on a script that queries a database and displays the results as a line graph. Is there a way to loop through the results using a for loop rather than the while loop? I have attached code that just simply prints the values. I will worry about creating a graphic afterwards: <title>Database Test</title> </head> <body> <?php $connection = mysql_connect('mydb','user','pass');
14
1934
by: bchi49 | last post by:
I'm having problem updating a form that queries from 3 tables. When I update the foreign key it tries to update the PK on the foreign key table which it shouldn't. I'm using MS Access 2003 connected to SQL Server 2000. Here's an example: Tables: T1, T2, and T3. T1 links to T2, and T2 links to T3.
9
7433
by: Petr Vileta | last post by:
Hi, I'm new here and excuse me if this question was be here earlier. I have a simple code <html><body> <?php <?php $link = mysql_connect("localhost", "user", "password") or die("Grr: " . mysql_error()); mysql_select_db("my_dbf") or die("Grr");
2
1655
by: William Gill | last post by:
given the query: SELECT * FROM customers left join addresses on customer.cusid=addresses.cusid The mysql monitor returns all fields from both tables, including repeating the field matching the on condition (cusid). mysql_fetch_array() does not return the matching field from the joined
0
9688
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
10260
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...
0
10030
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
9078
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...
1
7570
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
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();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.