Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7922237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:53:11+00:00 2026-06-03T16:53:11+00:00

I am new to PHP so please excuse my mess. This is a very

  • 0

I am new to PHP so please excuse my mess. This is a very complicated query for somebody like me to change.

Please see the query below. Right now all results are being displayed in the $row[‘Post’]; Instead I want to be able to do something like:

$somerow = $row[‘some_row’];
$somerow2 = $row[‘some_row2’];

and then be able to use it anywhere with the $variables used above.

I tried using this below but it didn’t work:

if($rows == 0)
{
print("");

}
elseif($rows > 0)
{
while($row = mysql_fetch_array($query))
{

$postid = htmlspecialchars($row['post_id']);
$postname = htmlspecialchars($row['post_name']);


print("$postname and the id is $postid");
}

}

How can i achieve this?

Full Query:

$denied = "Denied";
$userid = Drawn from db for user viewing;

$sql = "SELECT  concat(  (select client_name from user_accounts where 
User_id = tv.User_id), ' commanded ' , title_1  ,' on ', CAST(other_date AS 
CHAR(10)) ) AS Post FROM client_visits tv where User_id in (select contact_id 
from contacts where User_id = '$userid' ) and user_allowed = '$denied'
or User_id in (select User_id from contacts where contact_id = '$userid')
and user_allowed = '$denied'
union
SELECT  concat(  (select client_name from user_accounts where User_id 
= tv.User_id), ' commanded ' , title_2  ,' on ', CAST(other_date AS CHAR(10)) )
AS Post FROM client_notes tv where User_id in (select contact_id from 
contacts where User_id = '$userid' ) and user_allowed = '$denied'
or User_id in (select User_id from contacts where contact_id = '$userid')
and user_allowed = '$denied'
union
SELECT  concat(  (select client_name from user_accounts where User_id 
= tv.User_id), ' commanded ' , title_3  ,' on ', CAST(other_date AS CHAR(10)) )
AS Post FROM client_media tv where User_id in (select contact_id 
from contacts where User_id = '$userid' ) and user_allowed = '$denied'
or User_id in (select User_id from contacts where contact_id = '$userid')
and user_allowed = '$denied'
union
SELECT  concat(  (select client_name from user_accounts where User_id 
= tv.User_id), ' commanded ' , title_4  ,' on ', CAST(other_date AS CHAR(10)) )
AS Post FROM client_stats tv where User_id in (select contact_id from 
contacts where User_id = '$userid' ) and user_allowed = '$denied'
or User_id in (select User_id from contacts where contact_id = '$userid')
and user_allowed = '$denied'
union
SELECT  concat(  (select client_name from user_accounts where User_id 
= tv.User_id), ' commanded ' , title_5 ,' on ', CAST(other_date AS CHAR(10)) )
AS Post FROM client_current_list  tv
where User_id in (select contact_id from contacts where User_id = '$userid' )
and user_allowed = '$denied'
or User_id in (select User_id from contacts where contact_id = '$userid')
and user_allowed = '$denied'
union
SELECT  concat(  (select client_name from user_accounts where User_id 
= tv.User_id), ' commanded ' , title_6 ,' on ', CAST(other_date AS CHAR(10)) )
AS Post FROM client_past  tv
where User_id in (select contact_id from contacts where User_id = '$userid' )
and user_allowed = '$denied'
or User_id in (select User_id from contacts where contact_id = '$userid')
and user_allowed = '$denied'
union
SELECT  concat(  (select client_name from user_accounts where User_id 
= tv.User_id), ' commanded ' , title_7  ,' on ', CAST(other_date AS CHAR(10)) )
AS Post FROM  client_listers  tv
where User_id in (select contact_id from contacts where User_id = '$userid' )
and user_allowed = '$denied'
or User_id in (select User_id from contacts where contact_id = '$userid')
and user_allowed = '$denied'
union
SELECT  concat(  (select client_name from user_accounts where User_id 
= tv.User_id), ' commanded ' , title_8  ,' on ', CAST(other_date AS CHAR(10)) )
AS Post FROM    client_events  tv
where User_id in (select contact_id from contacts where User_id = '$userid' )
and user_allowed = '$denied'
or User_id in (select User_id from contacts where contact_id = '$userid')
and user_allowed = '$denied'
union
SELECT  concat(  (select client_name from user_accounts where User_id 
= tv.User_id), ' commanded ' , title_9  ,' on ', CAST(other_date AS CHAR(10)) )
AS Post FROM    client_admissions  tv
where User_id in (select contact_id from contacts where User_id = '$userid' )
and user_allowed = '$denied'
or User_id in (select User_id from contacts where contact_id = '$userid')
and user_allowed = '$denied'
union
SELECT  concat(  (select client_name from user_accounts where User_id 
= tv.User_id), ' commanded ' , title_10  ,' on ', CAST(other_date AS CHAR(10)) )
AS Post FROM    client_immu  tv
where User_id in (select contact_id from contacts where User_id = '$userid' )
and user_allowed = '$denied'
or User_id in (select User_id from contacts where contact_id = '$userid')
and user_allowed = '$denied'";

$query = mysql_query($sql) or die ("Error: ".mysql_error());

$result = mysql_query($sql);

if ($result == "")
{
echo "";
}
echo "";


$rows = mysql_num_rows($result);

if($rows == 0)
{
print("");

}
elseif($rows > 0)
{
while($row = mysql_fetch_array($query))
{

print($row['Post']);
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:53:14+00:00Added an answer on June 3, 2026 at 4:53 pm

    You could store each row in an array and later on pick the rows out you want to use.

    if($rows == 0)
    {
        print("I have no rows!");
    }
    else
    {
       $allrows = array();
       while($row = mysql_fetch_array($query))
       {
           $allrows[] = $row;
       }
       $row1 = $allrows[0];
       $row2 = $allrows[1];
       echo $row1['Post']; // Print out first row
       echo $row2['Post']; // Print out second row
       var_dump($allrows); // Print out all the rows and the structure of this array
    }
    

    If you then want to use those variables everywhere, you will need to make them global, but I would advice against using global variables for things like that or for anything in general for that matter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to MVC and php framework, so please excuse me for this simple
please see: http://pastebin.com/5za3uCi1 I'm quite new to php and I'm editing the ventrilo status
I'm quite new to PHP and CodeIgniter, so please excuse me for posting up
I am new to PHP so please forgive if this question or problem seem
I'm new to PHP so please forgive me if this is a stupid question.
I'm new to Quartz Composer so please excuse if this is obvious ... I
I'm pretty new to PHP, so please forgive me if this question is obnoxiously
I am fairly new to PHP so please bear with me :) What I
i am new in php i have a problem in my php code.please help
Rather new to php, so sorry if this seems stupid. I'm really copying a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.