Jump to content

2 Queries become one


thefollower

Recommended Posts

Is there a way to merge this:

 

$Getreports = mysql_query("SELECT * FROM textmessages WHERE Status = '3' AND Staff='0' ORDER BY `SentTime` ASC")
or die(mysql_error());
$GetReports2 = mysql_query("SELECT * FROM phonecalls WHERE Status = '3' AND Staff='0' ORDER BY 'SentTime' ASC")
or die(mysql_error());

 

So that when i do:

 

while(mysql_fetch_assoc($Getboth)    < it will alternate between each query per row?

Link to comment
Share on other sites

use a join

 

example

 

SELECT table1.fileld1, table.field2, table2.field1, table2.field2, FROM

table1

INNER JOIN

table2 ON table1.common_column = table2.common_column

WHERE

common_column = value

 

now if you want to return values from both tables that happen to be in columns of the same name, use an alias

 

SELECT table1.field1 AS t_field1, table2.field1 as tt_field1 ...

Link to comment
Share on other sites

It's not very good practice to have repeating data in your database tables.  You should only need it in one table and then link them in the database.  I would recommend you consider looking into re-organizing your DB layout now before you get too deep.

Link to comment
Share on other sites

It's not very good practice to have repeating data in your database tables.  You should only need it in one table and then link them in the database.  I would recommend you consider looking into re-organizing your DB layout now before you get too deep.

 

Just by looking at hsi table names I can see how it is necessary for him to repeat the same data in both tables...

Link to comment
Share on other sites

use a join

 

example

 

SELECT table1.fileld1, table.field2, table2.field1, table2.field2, FROM

table1

INNER JOIN

table2 ON table1.common_column = table2.common_column

WHERE

common_column = value

 

now if you want to return values from both tables that happen to be in columns of the same name, use an alias

 

SELECT table1.field1 AS t_field1, table2.field1 as tt_field1 ...

 

 

So :

 

SELECT textmessages.Status, textmessages.Staff, phonecalls.Status, phonecalls.Staff FROM
textmessages
INNER JOIN
phonecalls ON 

// dont know what to put below:
textmessages.common_column = table2.common_column
WHERE
common_column = value

 

Dont quite get the last bit.. which column is the common one?

Link to comment
Share on other sites

Well the only real connection is the fact that Status =  3

 

 

Because that means 3 = "reported" by a user.

 

Which is what im doing.. but rather than staff having to look through a table of reported text messages

And then a separate table for phonecalls I thought i shall interlink them.. so that staff don't keep prioritizing the first table on the page.

 

Before hand i have:

List of reported text messages:

rows etc

rows

rows

 

then i had:

List of repoted phone calls:

Rows

rows

rows

 

 

And staff kept ignoring the phone calls cos it was further down the page so i want them interlinked so staff don't know which one is which thus theres none being neglected from sheer laziness of scrolling down the page :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.