Lost Password?

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

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

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, 10:14 AM
Lop's Avatar   
Lop Lop is offline
Speaks fluent binary
 
Join Date: May 2006
Posts: 1,149
Credits: 112
Rep Power: 16
Lop 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, 05:07 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,234
Last Blog:
Passwords
Credits: 872
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
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, 03:58 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 7,302
Last Blog:
Tramp Variables
Credits: 1
Rep Power: 20
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
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.
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

Don't hesitate to ask any questions that you have! Check out our
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
!
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

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


All times are GMT -5. The time now is 03:34 AM.

Contest Stats

Xav ........ 1276.19
MeTh0Dz|Reb0rn ........ 1048.58
morefood2001 ........ 879.43
John ........ 872.39
marwex89 ........ 869.98
WingedPanther ........ 761.06
Brandon W ........ 684.87
chili5 ........ 294.12
Steve.L ........ 216.18
dargueta ........ 192.86

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 81%

Ads