Jump to content

gevensen

Members
  • Posts

    206
  • Joined

  • Last visited

Posts posted by gevensen

  1. Im looking to search back 90 days for example but it only returns say the last 2 weeks, if i increase it i see other records but still not the full number

    any ideas?

     

    SELECT * FROM sc_income WHERE full_name = 'Smith, John' AND date >= CURRENT_DATE - '90'

  2. Cheers for that, it has certainly tidied up my code, though if I wanted to take that information that I have got from that field and manipulate it how would I do that.

     

    For instance. it's used to judge how many tokens someone has. If they buy 10 more tokens I need to manipulate the data to add 10 more to the total.

     

    Is $result the variable I need to do this?

     

    if you want the records returned use for example $num=mysql_num_rows($result); that gives you the number of rows returned

    i
    f($num>10){
    //whatever
    }

    or even

     if(mysql_num_rows($result)>10){
    //whatever
    }

  3. 1st all in your query i do it like this for clarity, and if you use `` you have to use it on all not partially

    hope this sends you in the right direction

     

    $query="SELECT `Tokens` FROM `tokens` WHERE `CompNumber` ='2' ";
    $result = mysql_query($query); 
    if($result)
    {
    while($row=mysql_fetch_array($result))
    {
    echo $row[0]."<br />";
    
    }
    echo "all done!<br />";
    
    }
    

  4. that why i printed my data to the screen i usually catch errors easily that way but it didnt show the additional whitespace

    it just showed for example 'account' which looked normal not 'account

    ' which would look abnormal

    but thanks for the heads up you mentioned it early on but i didnt have problems with any other reports for whatever reason

    thanks again

  5. I have a query that works fine on myphpadmin but does not return a value using mysql_query in php

     

    its is a SUM function

     

    the field is a decimal 10,2

     

    index is set

     

    is there something in the mysql setup i could be doing wrong it should be working

    mysql_connect($servername, $dbusername, $dbpassword) or die(mysql_error());
    $dbname=$_SESSION['db'];
    mysql_select_db($dbname) or die("CANNOT SELECT DATABASE - ". mysql_error());
    $year='2009'; //$_SESSION['ytd_year'];
    $query="SELECT * FROM sc_business_report ";
    $result=mysql_query($query) or die(mysql_error());
    if($result){
    while($row=mysql_fetch_array($result)){
    $fund=$row['fund'];
    $account=$row['account'];
    $query2="SELECT SUM( `split_amount` )AS `total` 
    FROM `sc_expenses_transactions` 
    WHERE  `fund` = '$fund' 
    AND `account` = '$account'  
    AND YEAR ( `date_of_split` ) = '$year'  ";
    
    
    
    $result2=mysql_query($query2) or die(mysql_error());
    if($result2){
    	$row2=mysql_fetch_assoc($result2);
    	echo $query2."<br />";
    	echo "<br />VAR DUMP<br />";
    	var_dump($row2);
    	echo "<br />VAR DUMP<br />";
    	echo $row2['total']."<br />";
    } // eof result2
    mysql_free_result($result2);	
    }// eof while
    
    } //eof result

     

     

  6. $row2=mysql_fetch_row($result2)or die(mysql_error());

    FIXED

     

    VAR DUMP

    array(1) { ["total"]=> NULL }

    VAR DUMP

     

    No other error codes

    ini_set("display_errors", "1");
    error_reporting(E_ALL); 

     

    I pulled out the session and changed to to '2009'

     

     

     

    The or die(mysql_error()); on the mysql_fetch_row() line of code has no meaning because mysql_fetch_row does not set a mysql_error(). The only result you would get from the or die() would be for your code to stop execution with nothing being output by that statement. Remove the or die() -

    $row2=mysql_fetch_row($result2)or die(mysql_error());

     

    It would sure help if you posted the output you are getting. What does print_r($row2); actually show? What does the following show right after the line where $query2 is being set -

     

    var_dump($query2);

     

    What does adding the following two lines of code immediately after your first opening <?php tag on the page show -

    ini_set("display_errors", "1");
    error_reporting(E_ALL); 

     

    And since you happen to be using $_SESSION variables (it pays to show us everything you are doing on the page as it can be relevant to problems you are having on a page), what does a phpinfo() statement show for the register_globals setting? And if register_globals are ON, do any of your $_SESSION variables have the same name as any of your program variables.

  7. Example of output for

     

    $result2=mysql_query($query2) or die(mysql_error());
    if($result2){
    	$row2=mysql_fetch_assoc($result2);
    	echo $query2."<br />";
    	echo "<br />VAR DUMP<br />";
    	var_dump($row2);
    	echo "<br />VAR DUMP<br />";
    	echo $row2['total']."<br />";
    } // eof result2

     

    Sample of actual output should be 7219.35

     

    SELECT SUM( `split_amount` )AS `total` FROM `sc_expenses_transactions` WHERE `fund` = 'General' AND `account` = '2007 Debt ' AND YEAR ( `date_of_split` ) = '2009'

     

    VAR DUMP

    array(1) { ["total"]=> NULL }

    VAR DUMP

  8. i rewrote a smaller portion same problem

    this is the whole code

    in phpmyadmin the query displays a sum

    but print_r($row2); shows an empty array

    if i use echo $row2[0]; i get null also

     

    any takers?

     

    mysql_connect($servername, $dbusername, $dbpassword) or die(mysql_error());
    $dbname=$_SESSION['db'];
    mysql_select_db($dbname) or die("CANNOT SELECT DATABASE - ". mysql_error());
    $year=$_SESSION['ytd_year'];
    $query="SELECT * FROM sc_business_report ";
    $result=mysql_query($query) or die(mysql_error());
    if($result){
    while($row=mysql_fetch_array($result)){
    $fund=$row['fund'];
    $account=$row['account'];
    $query2="SELECT SUM( split_amount ) FROM sc_expenses_transactions WHERE  fund = '$fund' AND account = '$account'  AND YEAR ( date_of_split ) = '$year'  ";
    $result2=mysql_query($query2) or die(mysql_error());
    if($result2){
    	$row2=mysql_fetch_row($result2)or die(mysql_error());
    	print_r($row2);
    } // eof result2
    mysql_free_result($result2);	
    }// eof while
    
    } //eof result

  9. yes it is but i have renamed them all??

     

     

    $query="SELECT * FROM `sc_business_report` ";
    $result=mysql_query($query)or die(mysql_error());
    while($row=mysql_fetch_assoc($result))
    {
    $fund=$row['fund'];
    $account=$row['account'];
    print_r($row); echo "<br />";
    echo $fund."-".$account."<br />";
    $income_amount=0.00;
    $expense_amount=0.00;
    
    
    $query2="SELECT SUM(`amount`) FROM `sc_income_data` WHERE `fund` = '$fund' AND `account` = '$account'  AND YEAR(`date`) = '$year' ";
    echo "INCOME QUERY : ".$query2."<br />";
    $result2=mysql_query($query2)or die("error a :".mysql_error());
    if($result2){
    	$income_row=mysql_fetch_array($result2);
    	$income_amount=$income_row[0];
    	echo "Income Amount :".$income_amount."<br />";
    }
    
    
    $query3="SELECT SUM(`split_amount`) FROM `sc_expenses_transactions` WHERE `fund` = '$fund' AND `account` = '$account' AND YEAR(`date_of_split`) = '$year' ";
    echo "EXPENSE QUERY : ".$query3."<br />";
    $result3=mysql_query($query3)or die("error b :".mysql_error());
    if($result3){
    	$expense_row=mysql_fetch_array($result3);
    	$expense_amount=$expense_row[0];
    
    	}
    
    
    $query4="UPDATE `sc_business_report` SET `income` = '$income_amount' , `expense` = '$expense_amount' WHERE ( `fund` =  '$fund' AND `account` = '$account' ) ";
    mysql_query($query4)or die(mysql_error());
    
    
    }
    

  10. The mysql query is good

    It returns a sum in phpmyadmin

    but i cant seem to get the sum over to $expense_amount

    the $expense_row=mysql_fetch_array($result3); comes up with an empty array?

    what am i doing wrong?

     

    $query3="SELECT SUM(`split_amount`) FROM `sc_expenses_transactions` WHERE `fund` = '$fund' AND `account` = '$account' AND YEAR(`date_of_split`) = '$year' ";
    $result3=mysql_query($query3)or die("error b :".mysql_error());
    if($result3){
    	$expense_row=mysql_fetch_array($result3);
    	$expense_amount=$expense_row[0];
    	}

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.