Hello,

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

Recommended Answers

All 6 Replies

Member Avatar for diafol

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

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???

Member Avatar for diafol

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.

@taywin: mysql_fetch_array returns by index and by name both by default.

Ah I see. I usually use mysqli, so I thought it would be similar. Thanks.

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());

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.