Person Posted May 23, 2007 Share Posted May 23, 2007 <?php $host = ""; $user = ""; $pass = ""; $dbname = ""; $con = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>"); mysql_select_db($dbname); $yesterday = date('20ymd', mktime(0, 0, 0, date("m") , date("d") - 1, date("Y"))); $query= "SELECT SUM(1) AS clicks, SUM(`clcpc`), SUM(`chcpc`) FROM `nuke_pnAffiliate_clicktracking` WHERE `pl` = 'rpu' AND `date` = '" . $yesterday . "'"; $result= mysql_query($query); $row= mysql_fetch_assoc($result); echo $result ; ?> should print : clicks SUM(`clcpc`) SUM(`chcpc`) 211 38.299999821931 84.569998212159 but it prints : Resource id #5 How do i fix this ? Quote Link to comment Share on other sites More sharing options...
trq Posted May 23, 2007 Share Posted May 23, 2007 You need to print the $row array, not $result. mysql_query returns a result resource. Quote Link to comment Share on other sites More sharing options...
Person Posted May 23, 2007 Author Share Posted May 23, 2007 so how do i go about printing that ? would i just echo $row ? Quote Link to comment Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 echo $row[clicks].$row[]...... Quote Link to comment Share on other sites More sharing options...
Person Posted May 23, 2007 Author Share Posted May 23, 2007 its only printing clicks.... ? echo $row[clicks].$row[chcpc].$row[clcpc] ; Anyone know how it prints it in the Mysql admin ? Thats how i want it to print with the tables, but im new to this and have no idea how to do that... Quote Link to comment Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 because on your query, your not renaming the columns to chcpc... you need to either use $row['SUM(chcpc)']; or add to your query sum() "as chcpc" Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 23, 2007 Share Posted May 23, 2007 Change <?php $query= "SELECT SUM(1) AS clicks, SUM(`clcpc`), SUM(`chcpc`) FROM `nuke_pnAffiliate_clicktracking` WHERE `pl` = 'rpu' AND `date` = '" . $yesterday . "'"; $result= mysql_query($query); $row= mysql_fetch_assoc($result); echo $result ; ?> to <?php $query= "SELECT SUM(1) AS clicks, SUM(`clcpc`) as clcpc, SUM(`chcpc`) as chcpc FROM `nuke_pnAffiliate_clicktracking` WHERE `pl` = 'rpu' AND `date` = '" . $yesterday . "'"; $result= mysql_query($query); $row= mysql_fetch_assoc($result); printf("%d %02.12f %02.12f",$row['clicks'],$row['clcpc'],$row['chcpc']); ?> Ken Quote Link to comment Share on other sites More sharing options...
Person Posted May 23, 2007 Author Share Posted May 23, 2007 Ok now that, that problem is fixed .... is there a way i can put a table round it ? Like in the mysql admin ? Is there some type of php code to do this ? or would i have to make the table the manual way ? Quote Link to comment Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 echo '<table><tr><td>'.$yourvarshere.'</td></tr></table>'; Quote Link to comment Share on other sites More sharing options...
Person Posted May 23, 2007 Author Share Posted May 23, 2007 so there is no way i can build the table around the data ? so if there is more data there is more parts of the table to populate ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.