473,387 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Database Table Display Problem

ribbo
9
Hello everyone,

I have been trying to solve this problem for too long now, and was hoping someone maybe able to help me solve my problem.

I basically want to be able to UNION 2 tables together and order the contents by date and time.

i.e.

Honda Civic 01/02/08 10:45am (From database CARS)
Chevy Cobalt 01/02/08 11:45am (From database CARS)
Ford F-50 02/03/08 1:05pm (From database TRUCK)

[php]
<?php

require('config.php');

$result = mysql_query("(SELECT * FROM cars) UNION (SELECT * FROM truck) order by date desc, time desc");
while($row=mysql_fetch_array($result))
{
$make=$row["make"];
$model=$row["model"];
$date=$row["date"];
$time=$row["time"];

echo "$make";
echo "$model";
echo "$date";
echo "$time";
}

?>
[/php]

I appreciate any help :)
Feb 19 '08 #1
5 1035
Markus
6,050 Expert 4TB
and what output does that give you?
Feb 19 '08 #2
ribbo
9
hey, all i get is a blank screen.

I have data in the tables, and i can display 1 table at a time if i take out [php]UNION (SELECT * FROM truck)[/php] etc..

I just don't get it.
Feb 19 '08 #3
ribbo
9
Really really sorry about this.

MySQL Error: The used SELECT statements have a different number of columns

i just read another post from a moderator and said to not forget to add the error handling.

:(
Feb 19 '08 #4
ribbo
9
What an idiot. i have now figured out my own problem due to the error code.

Lesson learned!
Feb 19 '08 #5
Markus
6,050 Expert 4TB
Try doing
[php]
SELECT `col1`,`col2`,`col3` FROM `table_1`
UNION
SELECT `col1`, col2`, col3` FROM `table_2`
[/php]
Or something like that.. not sure.

EDIT: Just saw your last post... Silly me!

Post up your revised code; this could help someone else ;)
Feb 19 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Cpt. Zeep | last post by:
Although this is not strictly PHP related question, i presume lots of you are good in MySql so maybe you could help me. I am making sort of yellowpages application and have following issue: I...
11
by: HolaGoogle | last post by:
hi all, can you please tell me what i should do to avoid session timeout when displaying my database info in my asp form (DisplayUserDatabase.asp)??? ** actualy it does load and display the...
2
by: Mike | last post by:
Hi I have been tasked with converting my pulp and paper mills weekly projected and actual contractor hrs excel spreadsheet into a an Access 97 database. So far my design has been to use a...
1
by: jy836 | last post by:
Hey again. Thank you to everyone who responded to my question in the "Newbie database question" thread. I've got a new problem, though. ;-) I linked to an Access 2000 database. This database has...
0
by: clintonG | last post by:
I applied aspnet_regsql to SQL2K which was working fine throughout Beta 2 development. After installing Visual Studio and SQL Express RTM my application has blown up. Logging in to the application...
1
by: r2destini | last post by:
Hi Friends, I am new to .Net. So I don't know much. I am facing a problem in updating database through ADO.Net I am creating the dataset and there is no problem in the updation and...
10
by: chris.withers | last post by:
I have built a web portal and was considering adding a 'user mail' feature for users to message each other. I'm a bit uncertain on how to design the DB, so was wondering if there is a standard to...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
10
by: eholz1 | last post by:
Hello Members, I am setting up a photo website. I have decided to use PHP and MySQL. I can load jpeg files into the table (medium blob, or even longtext) and get the image(s) to display without...
10
by: darrel | last post by:
Hi there vb genius... I have a problem, i'am currently doing a program that has a database on it. i'am using access database, my problem is the records on my database table doesnt appear on my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.