I have been breaking my head here and I can't figure out what I am doing wrong, I am trying the get the result of the first query into variables to then run the second query. It works inside mysql but not insite my php query.

        $data = mysql_query("select * from (select * from logsbk ORDER BY id DESC) AS x GROUP BY dbname") or die(mysql_error()); 
            while($info = mysql_fetch_array( $data )) { 

            $now = $info['now'];
            $rjw = $info['dbname'];

            $presize = mysql_query('SELECT dbname AS "dbname2",SUM((size) / 1024) AS "size2" from logsbk WHERE dbname = '$rjw' AND now = '$now'') or die(mysql_error());

                    while($info2 = mysql_fetch_array( $presize )) { 
                        $now2 = $info2['size2'];
                        $rjw2 = $info2['dbname2'];
                        echo "<BR>";
                        echo $rjw2." ".$now2;



This turns out blank... no info, etc

3 Years
Discussion Span
Last Post by gcclinux

Erk - it looks like you're running loads of queries. You could probably do this with one query using an INNER JOIN.

The syntax in the second query looks mashed - take out the quotes

Edited by diafol


Hmm... isn't mysql_fetch_array returned an array, not a hash (as opposed to what you are using now)? So using $info['now'] would not be correct. What you should be using is $info[0]??? Or just use mysql_fetch_assoc instead???

Edited by Taywin


Well he shouldn't really be using mysql_* functions anyway, but that's another story.

What are you trying to do. If you explained what you were trying to achieve it would help.I get the first query:

"get the last record entered for each dbname" (correct me if I'm wrong)

The second query makes no sense to me as you're querying the SAME table ... oh sod it, lost the thread, literally... explain what you're doing and why.


Thank you for the interrest, I have figured it out and it was todo with my quotes/double quotes and also special characters.

Working code:

$presize = mysql_query("SELECT dbname AS "dbname2",SUM((size) / 1024) AS "size2" from logsbk WHERE dbname = \"$rjw\" AND now = \"$now\"") or die(mysql_error());

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.