CPressland Posted November 30, 2010 Share Posted November 30, 2010 Hey Guys, This is the first major PHP script I would have written, I know very little about both MySQL and PHP but can get myself around on both of them, Basically we have a database with a massive amount of data, what I want is a script that'll do something like this: select * from contaque_list where list_id in ( '914400', '914401' ); Then tell me the total number of records followed by the percentage of 'NEW' on the 'status' field. So how do I go about, connecting to the database and displaying the information I need? Thanks Guys Chris Link to comment Share on other sites More sharing options...
0 Olemus Posted November 30, 2010 Share Posted November 30, 2010 All the information you'll need is in the PHP manual http://www.php.net/manual/en/book.mysql.php The list of functions is pretty self explanatory, have a look through and post if your still stuck. Link to comment Share on other sites More sharing options...
0 +Dick Montage Subscriber² Posted November 30, 2010 Subscriber² Share Posted November 30, 2010 followed by the percentage of 'NEW' on the 'status' field. I think we'd need to see your schema before we understood what that means? Quick suggestion? Can you not connect Excel to this data source and use a pivot table? Link to comment Share on other sites More sharing options...
0 game_over Posted November 30, 2010 Share Posted November 30, 2010 a start would be.. // Make a MySQL Connection mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("db_name") or die(mysql_error()); $query = 'SELECT * FROM contaque_list WHERE list_id = 'value/$variable''; $result = mysql_query($query); //and to count $queryCount = 'SELECT count(*) FROM contaque_list'; $resultCount = mysql_query($queryCount); $fetch_row = mysql_fetch_row($resultCount); $numrows = $fetch_row[0]; // number of rows something along those lines anyway Link to comment Share on other sites More sharing options...
0 CPressland Posted November 30, 2010 Author Share Posted November 30, 2010 Thanks so far guys, I'm getting a Syntax Error on : $query = 'SELECT * FROM contaque_list WHERE list_id = '915721''; Any idea? Link to comment Share on other sites More sharing options...
0 CPressland Posted November 30, 2010 Author Share Posted November 30, 2010 Solved that with : $query = mysql_query("SELECT * FROM contaque_list WHERE list_id = '915721'"); Link to comment Share on other sites More sharing options...
0 CPressland Posted November 30, 2010 Author Share Posted November 30, 2010 Okay so going back to basics: This is what I have so far: <?php mysql_connect("192.168.20.10", "root2", "passwordexample") or die(mysql_error()); mysql_select_db("contaque") or die(mysql_error()); $query = mysql_query("SELECT count(*) FROM contaque_hopper WHERE campaign_id = 'CLOSERUK'"); $result = mysql_query($query); echo "Number :{$query} <br>"; ?> How can I get it to display the result of the MySQL Query on the echo bit? I'm just getting a 'Resource id #3' Link to comment Share on other sites More sharing options...
0 CPressland Posted November 30, 2010 Author Share Posted November 30, 2010 Okay so somebody was kind enough to help me and significantly changed my code, some of it is working, some of it isn't: <?php error_reporting(-1); ini_set('display_errors', true); $con = mysqli_connect( '192.168.20.10', 'root2', 'password', 'contaque' ); $res = mysqli_query( $con, "SELECT COUNT(*) AS 'total' FROM contaque_hopper WHERE campaign_id = 'CLOSERUK';" ); $res = mysqli_query( $con, "SELECT COUNT(*) AS 'callbk' FROM contaque_list WHERE status = 'CALLBK' and list_id > '910000' and list_id < '919999';" ); $res = mysqli_query( $con, "SELECT COUNT(*) AS 'new' FROM contaque_list WHERE status = 'NEW' and list_id > '910000' and list_id < '919999';" ); $row = mysqli_fetch_assoc($res); echo 'Buffer Status: ', (int)$row['total'], ' records.'; echo 'Number of 2H Callbks: ', (int)$row['callbk'], ' records.'; echo 'Number of New Leads ', (int)$row['new'], ' records.'; ?> Any further input guys? Link to comment Share on other sites More sharing options...
0 +theblazingangel MVC Posted November 30, 2010 MVC Share Posted November 30, 2010 you've got three queries each replacing the others results before you use them - they all return results to the same variable - $res, which you then get data from to put into $row. Therefore 'total' and 'callbk' do not exist in $row, only 'new'. copy the $row= line after each of the $res= lines, and move the echo statements to after each of the new $row= lines, and it should work! Edit: I see someone seems to have helped you with this in your other thread already, nevermind Link to comment Share on other sites More sharing options...
Question
CPressland
Hey Guys,
This is the first major PHP script I would have written, I know very little about both MySQL and PHP but can get myself around on both of them,
Basically we have a database with a massive amount of data, what I want is a script that'll do something like this:
Then tell me the total number of records followed by the percentage of 'NEW' on the 'status' field.
So how do I go about, connecting to the database and displaying the information I need?
Thanks Guys
Chris
Link to comment
Share on other sites
8 answers to this question
Recommended Posts