Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP






SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Loop Problem When Trying To Query Multiple MySQL Tables


I will try and explain this as best I can. I have a database with tables separated by year (exp. 1994data, 1995data, 1996data, etc.). I am trying to perform a search that will allow the user to enter a value, iterate through the tables and echo the result. Here is the code I am using: Code:




View Complete Forum Thread with Replies
Sponsored Links:

Related Messages:
Counting Multiple Mysql Tables In One Query
i know there is a count() feature and a join feature, but I am not sure as to how I am going to use these i need two simply count the rows from two tables, but need to do it in one query :-)

like mysql_num_rows("SELECT * FROM table, table"); the problem with this is that it multiplies the numbers of both tables together!

View Replies !   View Related
Loop Through Tables And Execute Query
I have a database that has many tables. How can I write php code to loop through all tables and run the following query:

LOOP THROUGH ALL TABLES {
     DELETE FROM {table_name} WHERE deleted = 1;
}

View Replies !   View Related
Accessing Query Data From Query Against Multiple Tables
I have a query that gets info from two tables in my database. How do I access the data from the query?

I know how to use the mysql_fetch_assoc() when the query in question only pulls information from a single table. How do I do the same thing for multiple tables and then insert the necessary data into my page? Code:

View Replies !   View Related
Can I Get PHP To Query From Multiple Tables?
I will have several tables in my database, several of which will contain similar products. Is there a way to set up my pages where PHP will get the items I request from EACH table?

View Replies !   View Related
Multiple Tables Query
Below I am adding all dollar amounts from a column in a table called transactions. Code:

View Replies !   View Related
Query Multiple Tables
I'm trying to run a query across three tables on my site - jobs, news, and articles. Each table has different field names - I've run a successful UNION query, but it hasn't allowed me to extract the fields I want - I keep getting column number errors. I found a very useful post from Leatherback saying to put the results into an array http://www.phpbuilder.com/board/show...t=union+fields:

I've come up with the following on the basis of that, but I keep getting "mysql_num_rows(): supplied argument is not a valid MySQL result resource" as an error. Could anyone advise why please? I'm not getting any SQL errors. PHP Code:

$search = $_GET['search'];
$newsquery = $connector->query("SELECT id, title, UNIX_TIMESTAMP(dateadded) AS dateadded, article FROM news WHERE article LIKE '%$search%'") or die ("Error in Query: $query.".mysql_error());;
$jobsquery = $connector->query("SELECT id, company, jobtitle, jobdesc, contact, UNIX_TIMESTAMP(dateadded) AS dateadded, UNIX_TIMESTAMP(closingdate) AS closingdate, oxford FROM jobs WHERE jobdesc LIKE '%$search%' ORDER BY dateadded DESC") or die ("Error in Query: $query.".mysql_error());;..........

View Replies !   View Related
Session To Query Multiple Tables & Fields
I'm trying to load up data where by the session is carrying the user ID.. and i need the session to call up the user table which is working fine. But i also need to call up info about gangs that the user is in. Now it gets complicated cos the user could be 1 of 30 members (30 being the max a gang gang can have).

But how is this done? This is what i got at the moment. But this is only calling up the one table. I need this now to also check if the user ID is in another table which could be in a possible 30 fields. Code:

View Replies !   View Related
Search Multiple Tables - Get The SQL Query Correct
I am trying to search mutiple tables in my PHP code. I believe I only need to get the SQL query correct. Basically I have maybe 5 table where I need t oselect all the data from them but I only want to search one of the fields in each of those tables.

I made a post on the SQL boards but I think it will involve more PHP now because I believe I need to use a join I have something like $search=$_POST["search"]; Code:

View Replies !   View Related
Select Query Problem - Multiple Tables
I have 4 database tables. I want to perform a query to loop through each table and display the results under the relevand heading as below. Code:

View Replies !   View Related
Nested Loop, 2 MySQL Tables
I have a set of nested links, and at one time each category one had all the
same subcategories. Now that has changed - each category has different
subcategories. I have a tree menu, but now it just shows all subs under
each category, of course. I have 2 tables - one for categories, one for
subcategories - they are related by the categoryID. I think I have the SQL
fine (have tried several different versions - see most recent/uncluttered
below), but how do I get it to work correctly in the tree loop?

SELECT DISTINCT cat.catName, cat.catDesc, subcat.subcatName
FROM cat, subcat
WHERE cat.catID = subcat.catID;

Tree example:
cat.catName(1)
subcat.subcatName(1)
subcat.subcatName(2)

cat.catName(2)
subcat.subcatName(3)
subcat.subcatName(4)

View Replies !   View Related
Multiple MySQL Tables
I need some help with tables in MySQL.
I am making a colums of articles in my site.
It has 3 posters that post articles.
I make a little serach page to search for words into articles.

I have the sintax below working, but I need to know what is the syntax
to it select words from several tables. Every table is for a poster
and all tables are in the same DB and have the same fields.

---------------
$searchword="SELECT * FROM table WHERE comment LIKE
'%$searchstring%'";
---------------

I tried
---------------
$searchword="SELECT * FROM table, table1, table2 WHERE selected_row
LIKE '%$searchstring%'";
---------------

and even make an ARRY for table, table1, table2 but it does not work.

View Replies !   View Related
Multiple Mysql Tables
I have a form that currently submits data to 1 mysql db. Now what I want to do is have an include form file that will allow to asociate supplier data for that product which will then add that data to a different mysql table. Then when I go and and look at a product I need to be able to see what suppliers sell that particluar product. I can't really post the code on the forum as its a 4 different files but I can either put up a web address that has the files on it that you can download or I can send them via email.

View Replies !   View Related
Query 2 Or More Tables MySQL PHP
Is is possible to use more than 1 table in an SQL query and if so how would you stucture it.

For example I am doing this site where there a 5 products and users log in to stock up on these products. The products are stored in a table along with a description and a path to a picture of the product. There is a second table that lists each product once for each user and stores that users buy price and mimimum stock qty.

I want to make a query that I can display the name, description, picture etc of each product that that user sells, but show it with their buy rate and minimum qty. Code:

View Replies !   View Related
MySQL Query Of 2 Tables
I have 2 tables,CurrentJobs and ItemTickets. Both tables have 'Reps'. I am trying to make query both tables to find out in 1 query what jobs have a certain Rep assigned to them. Here is my query that I have tried so far.

SELECT * FROM CurrentJobs, ItemTickets where CurrentJobs.Rep = 'Jared' && ItemTickets.Rep = 'Jared'

There are 4 rows in each table so I would think it would return 8 total rows,but it returns 16? I know it's something I don't understand about the join feature,but I tried to study different types of joins and I am even more confused. I need it to return the whole row of data and a lot of the other joins just return the requested field?

View Replies !   View Related
Selecting From Multiple Tables In MySQL.
I need help in trying to retrieve information from different tables, each one having a different primary key (auto-increment).

I have 3 pages, each accessing their respective tables.

(TABLE_internet_arts)
TagID (PK)
name
email
message
date
ip
time
profile_id
site_url
image_url
msg_type
site_title
page_title

(TABLE_losangeles_arts)
TagID (PK)
name
email
message
date
ip
time
profile_id
site_url
image_url
msg_type
site_title
page_title

(TABLE_sanfrancisco_arts)
TagID (PK)
name
email
message
date
ip
time
profile_id
site_url
image_url
msg_type
site_title
page_title

Right now, for each table on it's own, the SELECT statement looks like the following:

SELECT * FROM internet_arts ORDER BY TagID DESC LIMIT $offset, $rowsPerPage";

What I want to do is take the messages from all 3 tables and have them displayed, ordering them in chronological order by the date & time posted onto one page.

Anyone know the correct syntax and how to make the SELECT statement to do this?

View Replies !   View Related
MySQL Multiple Tables / Results
I would like to perform multiple queries to a MySQL database and have all
the results in 1 result set.

View Replies !   View Related
Selecting From Multiple Tables (Mysql)
The query works fine but I want print also table2 "Name" before the URL below.
I can only get the "Name" from table1.

Here´s the code:

$db = mysql_connect("host", "user", "pass"); mysql_select_db("database",$db);

$result = mysql_query("SELECT table1.CGrpId, table1.CustId, table2.Name, table1.Name FROM table1, table2 where table1.CGrpId=table2.CGrpId AND table1.RegCd=$variable",$db);

if ($myrow = mysql_fetch_array($result))

{ // display list if there are records to display

do {

printf("%s<a href=page.php?CGrpId=%s&codeid=$variable&CustId=%s>%s </a><br>
", $myrow["table2.name"], $myrow["CGrpId"], $myrow["CustId"], $myrow["Name"]);

} while ($myrow = mysql_fetch_array($result));

} else { // no records to display

echo "No information."; }

The "table2.Name" gives me a problem, it won´t print.

View Replies !   View Related
Joining Multiple Tables In MySQL
I'm wanting to join four tables, or at least this is what i think i need to do.
These are the table structures: Code:

View Replies !   View Related
Updating Multiple Tables In Mysql
I am trying to update a number of tables with the "if action=="update"" command on the attached page. however, when I try to run multiple updates in the same action or multiple actions for each update neither of them work.

View Replies !   View Related
Basic PHP / MYSQL Multiple Tables
I have two tables:

Categories (CatID, CatName)

Products (ProdID, CatID, ProdName)

Now, I would like to list all categories and their products on one PHP page. so it would look something like this:

Category 1
- prod 1
- prod 2
- prod 3
... etc

Category 2
-prod1
-prod2
-prod3
... etc

and so on for all the categories. Is there a sample where I can see how this can be done?

View Replies !   View Related
Mysql Query With While Loop
I need a function to generate and check order#'s to make sure of no dupes in the orders_id row of the orders table of a mysql db.

The thing is I am not sure where to start, I have found individual snippets but not sure how to merge them.

Outline of function:

1. Generate a random order# (based on dmyxxxx(xxxx being 0000 to 9999))

2. Check orders_id of orders table for duplicate

3 if dupe exists generate another order_id

4. do this a maximum of 10 times

5. if still dupe after 10 queries exit gracefulluy with trapable error (Bank payment module before starting)

6. if no dupe exists and return the order_id and a true flag so order can be inserted into the db.

View Replies !   View Related
Getting Info From Two Mysql Tables With One Query
I think the code is fairly self explanatory, so i'll post that first.

$query = "SELECT id,description,Title,tutorialtext,category," .
                 "DATE_FORMAT(timeadded, '%Y-%m-%d') as date " .
                 "FROM tutorial ORDER BY timeadded DESC LIMIT $max_items";

$query2 = "SELECT Name, catid," .
    "From tutorial_cats"

    $result = mysql_query ($query);

    while ($row = mysql_fetch_assoc ($result))Im probably missing something simple, but how do I combine query and query2 togther so that it gets both the things from tutorial, and from tutorial_cats?

View Replies !   View Related
Selecting From Multiple Tables In Mysql Database
I want to make an RSS feed displaying the latest updates on my website. My site has 3 sections: reviews, interviews and news. I want to combine them into 1 RSS feed.

So that means I have to find the 10 newest items throughout all 3 database tables. The problem is that the tables have some fields in common (like 'activated_dt', a datetime field) but not all.

What would be a good query to find the 10 newest items??

SELECT ID
FROM reviews,interviews,news
ORDER BY activated_dt DESC
LIMIT 10

But how do I know what table the ID is from?

View Replies !   View Related
Mysql Query With Near/endless Loop
I'm having a loop running in the folowing Query when I run it through Mysql command line (Only 1 row returns), but when I try it through a PHP page, it gets the "endless loop"...
Code:

View Replies !   View Related
MySQL Inserting Into Multiple Tables Linked Records
Using MySQL can anyone tell me how to most efficiently insert a collumn
in 'table1' retrieve the id from this record and insert mutliple
records into 'table2' with a collumn for the id in 'table1' which links
the two recordsets

View Replies !   View Related
Splitting Html Tables (from MySQL Query)
I have built a mySQL query that prints html tables. I need to split the tables into 2 equal parts. code:

View Replies !   View Related
MySQL Query Over 3 Tables And Return Results
I am having trouble coming up with a query for the database I designed. In its simplest form I have three tables:

Characters table | character data
voiceactors table | voice actor data
char_voice table | character ID and corresponding voiceactor ID

My problem is that seperately I can query all of the character information, then query again to get the corresponding voice actors for the character(there is often more than one) However, I can't figure out how to select the character information and the voice actors for that character in one query. Code:

View Replies !   View Related
MySQL Insert Query And A Foreach Loop
I am trying to insert the contents of an array into a database, with a separate row for each item of the array.

However, no matter what the size of the array, the last element is never inserted into the database, but a print or echo inside the loop prints each element of the array correctly. Any ideas? Code:

View Replies !   View Related
Results Of Same Field Names But Different Tables In MySQL Query.
I have a SQL string with a couple of JOINs that works perfectly in
command prompt. I get results for all the fields selected just fine.
But when I put it into a PHP page, I can't make variables(?) out of
fields that have the same field name from different tables.
Here's the SQL statement:

$sql = "SELECT orders.companyid,orders.ordernum,orders.address,tb l_ih_accounts.company,tbl_ih_accounts.address
FROM orderstatus ".
"LEFT JOIN orders ON (orderstatus.ordernum = orders.ordernum) ".
"LEFT JOIN tbl_ih_accounts ON (tbl_ih_accounts.id = ihid) ".
"WHERE submitted <> 'yes' ORDER BY orders.ordernum ASC";

Then in the "WHILE" clause after the database is queried:
$o_address = $row[orders.address];
$ih_address = $row[tbl_ih_accounts.address];

I've tried it without the table names in the $row statements, but then
I'll just get the results for tbl_ih_accounts.address.
I'm thinking there must be some way to uniquely "name" the results of
a particular field up in the SQL statement, and then just use that
unique name in the WHILE. But I have no clue, and can't find anything
about anything like that.

View Replies !   View Related
Maximum Execution Time Exceeded With A Mysql Query In A Loop
My script inserts a huge amount of rows to a mysql table and just as easy it deletes them, so to optimize the index numbers i'm trying to make it so that when i'm adding new rows it searches for an empty one to add the new one in.
It's a phpbb mod i'm writting. This is the code i'm trying: Code:

View Replies !   View Related
Inserting Data From Array Into MySQL Query Generated By While Loop
Without a doubt this issue is dead simple so please excuse the ignorance. Also not sure what I should search for to find a solution, which must already exist on the forum.

Here is my code without any repetition and it works fine. The id is retrieved from the database and is successfully passed to the query, which I have verified updates the categoryID for the correct row. Code:

View Replies !   View Related
Generating Multiple Alternating Columns And/or Tables Within Tables
I am having a little bit of trouble generating the code for a table with 2 columns. The columns contain tables within themselves. Not sure why as that part was an existing design. Here is the output so far and it is correct but not how i want it to be (i'll explain) Code:

View Replies !   View Related
Mysql Query Multiple Conditions.
Hi i want to do a mysql select with more than 1 conditions.

I have this:

select * from phpbb_posts where post_time = 1064078039;

but i want to be able to select multiple post_time's. I'm guessing it was something like this:

select * from phpbb_posts where post_time = (1064078039, 1034078039, 10640744039, 10643378039, 1064076039);

but thats obviously wrong. Anyone can help here?

View Replies !   View Related
Multiple Pages For One Mysql Query
how to get my mysql query to span over pages I would like it to be able to spread a large mysql query of over 100 over as many pages as needed. using maybe 50 results per page, or if that was adjustable it would make it even better..

View Replies !   View Related
Echo Multiple Row's From Mysql Query
Im not sure if im using the right logic her but Im trying to output multiple rows of data which = techid in the data table. The mysql data table consits of the following columns:

CALL_ID  ID  FirstName  EMail  LastName  cat_id  descrip  status  priority  phoneNumber  phoneExt  mobile  ticketVisi  pageView  TechID  cost  Time_Logged 

I have a function which is displaying ques Code:

View Replies !   View Related
Php Mysql Query Inserts My Data Multiple Times
I've been trying to execute a php script that inserts data into my MySQL database. The script works fine and inserts the data, but the problem is it inserts the data 3 times (and I've had it insert up to 5).

The query is correct as I have had it 'echo' out and it shows the query properly and when I copy it directly into my phpmyadmin SQL section, it executes only one time, so I'm not sure why it enters multiple times when executed through php.

The other weird thing is that I have an Apache server running on my computer for testing and sometimes the same script will insert multiple times on my computer, and only one time on my host server and vice versa.

Has anyone else ever experienced this problem? Any help would be appreciated. If you'd like to see a snippet of the code, let me know and I can paste it because it is a bit lengthy.

View Replies !   View Related
Selecting Multiple Values From Multiple Tables Using Checkboxes
I've been struggling with this for a bit but cannot seem to find a simpler, cleaner way of doing this.

a. I have a Table A - Customers , Table B - Contacts .
b. I have a form where a user types the first few alphabets of a customer name and then gets a list of contacts, cities.
c. The user is supposed to select multiple options from this list and then send that data to another form for processing.

I'm able to only pass data from Table A, not from B . Could someone please have a look at the 2 snippets of code and advise? And is there a way both these php scripts could be combined in a single one ? Code:

View Replies !   View Related
Grabbing Data From Multiple Tables For Multiple Requests
Here's what I'm trying to get at.

A table that displays all the Process Server's name, the number of summons's he has out within 7 days, 7-14 days and 15+ days...pretty simple, it's just a report so management can stay on top of how many papers are out.

I've got the server_information table with the server name and ID. and a case_information table with the serverID.

I've got a while loop that displays all the server's name, the problem is when I try to get the # of cases....here's what i've got so far. Code:

View Replies !   View Related
While Loop Two Tables
I am just getting started with some PHP/MySQL work and have come to a roadblock. I am going to be working on sites for bands and I want them to be able to update their site with their all their album information… I set up two tables in my database one for the albums and one for the tracks Code:

View Replies !   View Related
Multiple Users, Multiple Tables, One Form
I have a small group of users that will submit their 'goals' via one form (placed in a postnuke block). I have created one table (mysql) for each user to collect collect their goals. I need some direction in writing the php that will submit the form data to the correct table based upon the users Postnuke login.

View Replies !   View Related
Loop With Html Tables
I currently have it to where the user can input data and it is stored in a mysql db.. I am having problems with the output portion and it being formatted the way I would like it.

I want for it to print the all the data results inside of html tables...
5 across (columns) and 2 down (rows) so a total of ten records are printed out.  After 10 I want it to generate a second page with the next 10 records.. these records will all be sorted by date.. Code:

View Replies !   View Related
Creating A Loop For Html Tables
Nesting loops to create html tables with (incremented) variable names is a task I am weak at.

What I have is a quiz that lists each person in a row then shows the next name in the next row.

I could not figure out how to loop thru this, so I did it all by hand (I know, php would be more efficient, but I could not get it to work). Code:

View Replies !   View Related
Code Loop Through The Array And Delete Everything From Each Of The Tables
Will this code loop through the array and delete everything from each of the tables for a particular user. PHP Code:

$tables = array (
"user",
"user_info",
"foo",
"bar"
);
foreach ($tables as $value) {
DELETE * FROM $value WHERE user=$username
echo 'user deleted from '.$value;
}

Also is there a better way to delete all user info across multiple tables? This seems as if it could be quite inefficient.

View Replies !   View Related
Using Query Result To Do Another Query In Loop
I have 2 tables, one called users2 and one called books. Books has a field called UserId, which is the ID of the user that added the book to the database.

My problem, is that i need to take this ID from the book table, and use it to get some information from the user table. Here is my code to get the ID from the book table: Code:

View Replies !   View Related
AVG() Through Multiple Tables?
I'm trying to get the average of several columns [all with the name of SIR] in several different tables, and display the result. My code is giving me a "please check the manual depending on your MySQL version.." error. Here's my code:

View Replies !   View Related
Multiple Tables
Is there a way to truncate multiple tables in one query?This deletes all from only 1 table: PHP Code: $sql = "TRUNCATE table1"; $result = mysql_query($sql,$connection);I've tried to add "AND table2" but that's not working.

View Replies !   View Related
Multiple Tables
I'm putting together a shopping cart and have run into a problem. I have my cart table storing the users chosen shopping cart info, then multiple tables storing the details of each category of products. For example books, music , dvds etc. What I can't figure out is if it is possible to call multiple product records in my join statement. Can I loop through a list of my product categories somehow or how can I do this? PHP Code:

$sql= "select * from cart inner join $cat on cart.itemId = $cat.$catId where cart.cookieId = '" . GetCartId() . "' order by $cat.title asc";

View Replies !   View Related
Multiple While Loop
How would you do a loop inside a loop??? I've tried numerous ways, but have came up empty handed. Here is the code I have. Code:

View Replies !   View Related
Inserting Into Multiple Tables?
I need to increment the value of 'id' in 5 tables whenever it is incremented in another table.... Is there any way to do this? How?

View Replies !   View Related
Handles Multiple Tables
I have a roster script that handles multiple tables ($orderof) and within those tables multiple divisions ($sword). The only problem is that, nothing is getting displayed -- though there are no errors (systematic [to my knowledge] or parse). PHP Code:

View Replies !   View Related
Getting Data From Multiple Tables
I was wondering if anyone can tell me how to get data from several tables and save them in variables for further processing?

View Replies !   View Related
One Form, Multiple Tables
I have a form which is used insert data into multiple tables. Each table relies on the data inserted from the previous table. The problem I think I am having is that the data is not avialable by the time the next query is run. code:

View Replies !   View Related

Copyright © 2005-08 www.BigResource.com, All rights reserved