PHP isn't parsing mysql query

This started in the mysql forum and now it is a php issue.

This query when run in phpmyadmin,


$q2 = "
SELECT Attribute
     , Value 
  FROM radcheck
 WHERE Attribute = 'Max-All-Session' 
   AND Username = 'loren'
UNION 
SELECT Attribute
     , Value 
  FROM radcheck
 WHERE Attribute = 'Expiration' 
   AND Username = 'loren'
";


gives
Attribute Value
Max-All-Session 2592000
Expiration 1442281403

In the php side


$res = mysql_query($q2) or die(mysql_error()); 
$row = mysql_fetch_assoc($res);	
echo '<pre>'; var_dump($row); echo '</pre>';

This is the output

array(2) {
[“Attribute”]=>
string(15) “Max-All-Session”
[“Value”]=>
string(7) “2592000”
}

I’m looking for the expiration value but it just disappeared. Any ideas what I am doing wrong?

Any input is greatly appreciated.
Cheers.

we did warn you about the EAV scheme :slight_smile:

To what? I fail to see the question?

That is an awesome select.

This has been a learning day for me. I was really hoping I would not need a loop. I wanted to get it all in an array, kind of like the results of this.


SELECT Attribute
     , Value 
	 , id
	 , op
  FROM radcheck
 WHERE Username = 'loren'";

print_r on $row looks like,

Array
(
[Attribute] => User-Password
[Value] => wolsiffer
[id] => 97
[op] => :=
)

This is for a radius database and will be part of a larger query with 3 joins on 4 tables going on. I need data on each user such as total bandwidth used, time used, time used up and then I run that through a loop to get the data on each user.

I’m trying to avoid an additional query in the loop. The WHERE username = ‘loren’ will go away so that all users will be displayed and the results will be paged.

I’m almost ready to set up a separate table to hold the expiration value.

Thank you very much and hope there is an answer

It didn’t disappear, you only got the first row from the result set. If you use a while loop you’ll see the second row as well :slight_smile:

And by the way, you can get that result without UNION:


SELECT Attribute
     , Value 
  FROM radcheck
 WHERE Attribute IN ('Max-All-Session', 'Expiration')
   AND Username = 'loren'

I can see what I want cannot be done the way I want (stupid EAV). So now it’s an extra query or a storage table for expiration values. I think I will go out and pull petals off of a big flower :smiley:

Thank you all for your help, It is greatly appreciated.
Cheers

I think the questions lies somewhere between the following lines :shifty:

Can you post the code what you have so far to achieve the goal?