Jump to content

Data inside data listings .........


abemaca

Recommended Posts

hi , first ide like to say hello as this is my first proper post (i think lol) ive been reading the site for years and it has been most helpful so now its time for me to ask the question , so here goes ......

 

i run a network site and it users friends like most network sites do . when i login it gets my friends and there events , these are 2 different tables.

 

it shows the result in the order of friends , IE USER1 did this , USER1 did that , USER1 did this also , USER2 did this , etc etc

 

i need to to read in time posted but as its selecting friends 1st followed by there events it lists like above , how can i get it to read event times so it reads like this .... USER1 did this , USER2 did this , USER1 did that , USER2 did that , etc

 

any tips welcome and thanks for reading.

 

Link to comment
Share on other sites

<?

      $getfriends = mysql_query("SELECT contact FROM $tab[contacts] WHERE user='$id';");

        while ($friends = mysql_fetch_array($getfriends))

        {

 

      $getevents = mysql_query("SELECT event,time,img,vid,status,added FROM $tab[events] WHERE user='$friends[0]' ORDER BY time;");

              while ($event = mysql_fetch_array($getevents))

              {

 

Link to comment
Share on other sites

You can merge both of those queries into one using a JOIN

 

SELECT `e`.`event`,`e`.`time`,`e`.`image`,`e`.`vid`,`e`.`status`,`e`.`added`,`c`.`contact`
FROM `events_table` `e`, `contacts_table` `c`
WHERE `e`.`user` = `c`.`contact` AND `c`.`user` = $id

 

I haven't tested this though. I'll set up a demo table and see if it works

Link to comment
Share on other sites

i did before , this is what im using now ......

 

<?
       $getfriends = mysql_query("SELECT contact FROM $tab[contacts] WHERE user='$id';");
        while ($friends = mysql_fetch_array($getfriends))
        {
      
            $getevents = mysql_query("SELECT event,time,img,vid,status,added FROM $tab[events] WHERE user='$friends[0]' ORDER BY time;");
              while ($event = mysql_fetch_array($getevents))
              {?>

Link to comment
Share on other sites

That's php code, not a mysql query

 

i posted it elsewhere and it was staff that moved it here.

 

Also, why not just use a JOIN?

 

i didnt know about this , hence me posting it on a help site , to get some help !!!

 

someone asked me to paste what i used already , so i did.

 

i was then given another way to query , so i replaced mine for theres but it gave back error hence the followup questions.

Link to comment
Share on other sites

"SELECT e.event,e.time,e.img,e.vid,e.status,e.added, c.contact FROM $tab[contacts] AS c INNER JOIN $tab[events] AS e ON (  e.user =  c.contact ) WHERE c.user='$id' ORDER BY e.time"

 

ok i copied this in and NO errors , yippie ;)

 

this is how i have it now .....

 

<?
       $getfriends = mysql_query("SELECT e.event,e.time,e.img,e.vid,e.status,e.added, c.contact FROM $tab[contacts] AS c INNER JOIN $tab[events] AS e ON (  e.user =  c.contact ) WHERE c.user='$id' ORDER BY e.time;");
        while ($friends = mysql_fetch_array($getfriends))
        {

 

so how do i show results ??? before i would use <?=$friends[0]?> ...... but this dont work ???

 

thanks in advance for this help. great site

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.