Jump to content

Recommended Posts

Hey guys,

 

What my project does, is have user profiles and operation profiles, when adding an operation i can add a user that is involved in that operation.

 

Doing this populates a 'user_data' table with that users id to that operation id:

----------------------------------

|operation_dataoid | user_datauid |

----------------------------------

 

On a users profile i want to list the operation names that the user is involved with.

My attempt:

<?php 
$collect3 = @mysql_query("SELECT * FROM user_operation WHERE user_datauid = $uid");
while ($result3 = mysql_fetch_array($collect3))
{
$collect2 = @mysql_query("SELECT * FROM operation_data ");
$result2 = mysql_fetch_array($collect2);
$result2['oid'] = $result3['operation_dataoid'];

print "Operation ID: " . $result2['oid']; 

}
?>

$result3 uses the current userid to get all operation ids in that table associated with that uderisd.

$result2 gets the information from the operation_data (with its name etc) and i put the id gotten from the user_operation table and match it with the oid.

The print will get each operation, and sucessfully get the id of the operations the user is involved in and displays it.

However, i want the name of the operation aswell, how would i get this?

 

Thanks in advanced. =]

Link to comment
https://forums.phpfreaks.com/topic/120194-solved-displaying-dynamic-content/
Share on other sites

Thanks for the instant reply.

 

I've read up a bit on joins, but it is a bit confusing =[.

I tried: (With previous code still intact)

<?php 
$collect3 = @mysql_query("SELECT * FROM user_operation WHERE user_datauid = $uid");
while ($result3 = mysql_fetch_array($collect3))
{
$collect2 = @mysql_query("SELECT * FROM operation_data ");
$result2 = mysql_fetch_array($collect2);

$queryjoin = mysql_query("SELECT user_operation.operation_dataoid, operation_data.name 
						FROM user_operation 
						LEFT JOIN operation_data 
						ON operation_data.name = operation_data.oid
						WHERE user_operation.user_datauid = $uid") or die(mysql_error());
$result4 = mysql_fetch_array($queryjoin);
print $result4['name'] . "<br />";



}
?>

 

 

My DB Tables:

user_data table:
--------------
| uid | name |
--------------

operation_data table:
--------------
| uid | name |
--------------

user_operation:
-----------------------------------
| operation_dataoid | user_datauid |
-----------------------------------

 

As my attempt prints nothing, what am i doing wrong?

My head hurts =[

Well, I finally want to show the name of the operation (operation_data.name).

After changing the query JOIN from:

ON operation_data.name = operation_data.oid

To:

ON operation_data.oid = user_operation.operation_dataoid

 

And after displaying the results I get:

nbcxnxncn
nbcxnxncn

 

Basically 2 of the same operation. Should i get rid of the while loop.

while ($result3 = mysql_fetch_array($collect3)){}

And do a while loop on the JOIN query we just did?

 

UPDATE: I just got rid of the while loop i first did and did it on the JOIN query and it worked like a charm, thanks hugely for your help. :D

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.