Forum Moderators: coopster

Message Too Old, No Replies

mysql queries

         

drewst

10:37 pm on May 9, 2005 (gmt 0)

10+ Year Member



VERY SIMPLY
i have two tables both holding similar info (trust me its been normalized as far as pos)

anyway i query table1 and get results with headings

id, page

i then query table2 and get a table with
id and page

how can i add the rows together (union removed suplicates). I want to do this so i can count the number of occurences of pages. I can do this easy its just the adding of the rows together? any ideas or help maybe a sub or join may work

Thanks

Drew

buriedUnderGround

10:47 am on May 10, 2005 (gmt 0)

10+ Year Member



If I understand you correctly you could try something like :
"SELECT id, page, table_two.page AS page_two FROM table_one, table_two WHERE table_one.id=table_two.id"

You would then end up with id, page and page_two.

drewst

11:24 am on May 10, 2005 (gmt 0)

10+ Year Member



hi mate,

I dont think i have made this clear,ill elaborate

we have two tables

WEBSITE_HIT and SESSION_HIT

website_hit contain details on the visit_id and the page a user has entered on a website

session_hit is populated with subsequent hits from the same user still detailing page and visit_id. I have sepeated them simply for ease and making a majority of my queries easier to achieve.

i want to have a table with PAGE and VISIT_ID which almost concatonates the rows from WEBSITE_HIT and SESSION_HIT

so if there were 5 rows in hit and 7 rows in session i want 12 rows in my resulting table

Thanks

Drew

Sarah Atkinson

2:39 pm on May 10, 2005 (gmt 0)

10+ Year Member



just to clarify your wanting the resulting table to be html and not a new msql db table

drewst

2:48 pm on May 10, 2005 (gmt 0)

10+ Year Member



Hiya,

Im actually writing a font end in .net so into a datatable but not generating a new database table,

SOrry my description was a bit loose :)

Drew

Sarah Atkinson

2:49 pm on May 10, 2005 (gmt 0)

10+ Year Member



IF html table

couldn't you just do two queries and not add the closing </table> tag till after the querrie was finished?

$result = @mysql_query("SELECT id, other FROM $fromwhere WHERE something = $something);
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
?>
<table class="myTable">
<tr><th>Day</th><th>ID</th><th>Other</th></tr>

<?php
while ($row = mysql_fetch_array($result)) {
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['other'] . '</td>';
echo "</tr>";
}

$result2 = @mysql_query("SELECT id, other FROM $fromwhere2 WHERE something = $something);
if (!$result2) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}

while ($row = mysql_fetch_array($result2)) {
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['other'] . '</td>';
echo "</tr>";
}
?>
</table>

drewst

2:55 pm on May 10, 2005 (gmt 0)

10+ Year Member



Hi sarah,

You could do that to just kind of plonk them together but i want to further query the results table. e.g. count occurrences of certain pages and use some IN queries to further analyse the data

Thanks for the input :)

Drew

Sarah Atkinson

4:54 pm on May 10, 2005 (gmt 0)

10+ Year Member



drewst
I stickyed you
Sarah