Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-20-2006, 11:14 AM
Lop's Avatar   
Lop Lop is offline
Speaks fluent binary
 
Join Date: May 2006
Posts: 1,149
Rep Power: 18
Lop will become famous soon enoughLop will become famous soon enough
Default Arrays

I'm pulling data from a SQL DB and have to combine two tables. So I have a query that runs and inside the while calls another query and retrieves data based on the first query data.

I've created an array and am storing data in it but as I'm doing it I am thinking about how this can't be the best way. I need to store 6 values, 5 from one db and 1 from the other. In the while loop I assign the data like

PHP Code:
$myArray[i][0] = $row[...];
$myArray[i][1] = $row2[...]; // Value from second db
...... 
What is the best way to do this? I know there is a better way.
__________________
Lop
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 07-20-2006, 06:07 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

i believe you can query two tables using a UNION, however im not sure the exact syntax but i believe its something like

PHP Code:
(SELECT a FROM table1)
UNION
(SELECT b FROM table2
i think
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-21-2006, 04:58 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,203
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

Use a join

PHP Code:
<?php
// Make a MySQL Connection
// Construct our join query
$query "SELECT family.Position, food.Meal ".
 
"FROM family, food ".
    
"WHERE family.Position = food.Position";
Code taken from and for more information: http://www.tizag.com/mysqlTutorial/mysqljoins.php

This is MySQL code but the query should work the same with msSQL.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python arrays... Sir_Rimo Python 3 06-20-2007 09:54 AM
variable length arrays in C rattlepanos C and C++ 3 05-03-2007 12:35 PM
Arrays clookid PHP Tutorials 1 01-11-2007 09:30 PM
Arrays Sionofdarkness C and C++ 5 07-26-2006 06:35 PM
Arrays in NET 2.0 or CLI Managed C++ Void Managed C++ 1 07-18-2006 08:57 PM


All times are GMT -5. The time now is 07:18 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads