2

I have a PHP function view_activated_profile();. I want it to return a result for two different queries. I don't know if it's possible or not, but there must be some way to achieve full result on another page.

I have two pages, functions.php and profile.php. In functions.php, I have defined the functions:

$activated = check_activated();
while($row = mysql_fetch_array($activated))
{
    $userid = $row['admin_id'];
}

$query = "SELECT * from cv_user_profile WHERE admin_id=$userid";
$result = mysql_query($query);
$array1 = mysql_fetch_array($result);

$query2 = "SELECT * from cv_adminlogin WHERE admin_id=$userid";
$result2 = mysql_query($query2);
$array2 = mysql_fetch_array($result2);

$overall = $array1.$array2;

return $overall;

Then I called the function in profile.php like this:

$user_profile = view_activated_profile();

while($row = mysql_fetch_array($user_profile))
{
    $showfullname = $row['full_name'];
    $showjob_title = $row['job_title'];
    $showemail = $row['email_address'];
    $showdob = $row['dob'];
    $showmobile = $row['mobile'];
    $showphone = $row['phone'];
    $shownationality = $row['nationality'];
    $showprofilepic = $row['profile_image'];
    $showaddress = $row['address'];
    $showaboutme = $row['about_me'];
    $showlastupdated = $row['last_updated'];

}

I get this error on profile.php page:

Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\xampp\htdocs\aptanaProjects\pakistanihaider\admin\profile.php on line 30

Below are my database tables that i have used in queries: cv_adminlogin cv_user_profile

What i am doing wrong? How to get result of both queries successfully on profile.php?

4

2 に答える 2

2

You can do this in one query, by JOINing the two tables like so:

SELECT 
  u.*,
  a.*
from cv_user_profile u
INNER JOIN cv_adminlogin a ON a.admin_id = u.admin_id 
WHERE u.admin_id = '$userid'
于 2013-01-01T08:33:34.527 に答える
1

Use array_merge, to merge two or more than two array array,

Replace your line

$overall = $array1.$array2;

with

$overall = array_merge($array1,$array2);
于 2013-01-01T08:33:14.390 に答える