Modernvox Posted September 9, 2010 Share Posted September 9, 2010 Can't fix it? <?php include('connect.php'); mysql_query("SELECT itemQty SUM(itemQty) FROM transactions Where itemDescription= 'raffle'") or die mysql_error()); $row = mysql_fetch_array( $result ); echo $row['sum(itemQty)']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/212924-unexpected-t_string-in-this-short-query/ Share on other sites More sharing options...
fortnox007 Posted September 9, 2010 Share Posted September 9, 2010 would this help you? <?php include('connect.php'); $result = mysql_query("SELECT itemQty SUM(itemQty) FROM transactions Where itemDescription= 'raffle'") or die mysql_error()); $row = mysql_fetch_array( $result ); echo $row['sum(itemQty)']; ?> : ) i added $result = before you mysql_query(); Quote Link to comment https://forums.phpfreaks.com/topic/212924-unexpected-t_string-in-this-short-query/#findComment-1109009 Share on other sites More sharing options...
Modernvox Posted September 9, 2010 Author Share Posted September 9, 2010 would this help you? <?php include('connect.php'); $result = mysql_query("SELECT itemQty SUM(itemQty) FROM transactions Where itemDescription= 'raffle'") or die mysql_error()); $row = mysql_fetch_array( $result ); echo $row['sum(itemQty)']; ?> : ) i added $result = before you mysql_query(); Nope. Thanks for trying though:-) Quote Link to comment https://forums.phpfreaks.com/topic/212924-unexpected-t_string-in-this-short-query/#findComment-1109010 Share on other sites More sharing options...
fortnox007 Posted September 9, 2010 Share Posted September 9, 2010 Hmm I have closed my sql to test it, but arent you missing a loop at the bottom to run through the array of results? does maybe this work for you? <?php include('connect.php'); $result = mysql_query("SELECT itemQty SUM(itemQty) FROM transactions Where itemDescription= 'raffle'") or die mysql_error()); while ($row = mysql_fetch_array( $result )){ echo $row['sum(itemQty)']; } ?> if this doesnt work It might be the ['sum(itemQty)'] that is weird. But i hope this works Quote Link to comment https://forums.phpfreaks.com/topic/212924-unexpected-t_string-in-this-short-query/#findComment-1109012 Share on other sites More sharing options...
Modernvox Posted September 9, 2010 Author Share Posted September 9, 2010 Hmm I have closed my sql to test it, but arent you missing a loop at the bottom to run through the array of results? does maybe this work for you? <?php include('connect.php'); $result = mysql_query("SELECT itemQty SUM(itemQty) FROM transactions Where itemDescription= 'raffle'") or die mysql_error()); while ($row = mysql_fetch_array( $result )){ echo $row['sum(itemQty)']; } ?> if this doesnt work It might be the ['sum(itemQty)'] that is weird. But i hope this works Nope. Still nothing. I have tried $row['itemQty']; Quote Link to comment https://forums.phpfreaks.com/topic/212924-unexpected-t_string-in-this-short-query/#findComment-1109015 Share on other sites More sharing options...
fortnox007 Posted September 9, 2010 Share Posted September 9, 2010 This could be nothing but i just googled for http://www.parse-error-unexpected-t-string.com/ and if i look at your code Maybe a ( is missing right after the or die clause or die mysql_error()); instead of or die (mysql_error()); So maybe this is correct now: <?php include('connect.php'); $result = mysql_query("SELECT itemQty SUM(itemQty) FROM transactions Where itemDescription= 'raffle'") or die (mysql_error()); while ($row = mysql_fetch_array( $result )){ echo $row['sum(itemQty)']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/212924-unexpected-t_string-in-this-short-query/#findComment-1109016 Share on other sites More sharing options...
Modernvox Posted September 9, 2010 Author Share Posted September 9, 2010 This could be nothing but i just googled for http://www.parse-error-unexpected-t-string.com/ and if i look at your code Maybe a ( is missing right after the or die clause or die mysql_error()); instead of or die (mysql_error()); So maybe this is correct now: <?php include('connect.php'); $result = mysql_query("SELECT itemQty SUM(itemQty) FROM transactions Where itemDescription= 'raffle'") or die (mysql_error()); while ($row = mysql_fetch_array( $result )){ echo $row['sum(itemQty)']; } ?> Yep. That eliminated the error. Thank you. Although it still returns 0 results i at least know what u pointed out:-) Quote Link to comment https://forums.phpfreaks.com/topic/212924-unexpected-t_string-in-this-short-query/#findComment-1109018 Share on other sites More sharing options...
fortnox007 Posted September 9, 2010 Share Posted September 9, 2010 Cool : ) Btw i found a nice script for all your error stuff handling while reading some more: http://php.net/manual/en/function.mysql-error.php IN the comments are a few good ones Quote Link to comment https://forums.phpfreaks.com/topic/212924-unexpected-t_string-in-this-short-query/#findComment-1109019 Share on other sites More sharing options...
mikosiko Posted September 9, 2010 Share Posted September 9, 2010 Can't fix it? <?php include('connect.php'); mysql_query("SELECT itemQty SUM(itemQty) FROM transactions Where itemDescription= 'raffle'") or die mysql_error()); $row = mysql_fetch_array( $result ); echo $row['sum(itemQty)']; ?> you are missing a , after itemQty... your select should read mysql_query("SELECT itemQty, SUM(itemQty) AS TitemQty FROM transactions Where itemDescription= 'raffle'") or die (mysql_error()); notice that I also added an alias for the aggregate function... it will allow you to change this line echo $row['sum(itemQty)']; for the more simple echo $row['TitemQty']; Quote Link to comment https://forums.phpfreaks.com/topic/212924-unexpected-t_string-in-this-short-query/#findComment-1109023 Share on other sites More sharing options...
Modernvox Posted September 9, 2010 Author Share Posted September 9, 2010 Can't fix it? <?php include('connect.php'); mysql_query("SELECT itemQty SUM(itemQty) FROM transactions Where itemDescription= 'raffle'") or die mysql_error()); $row = mysql_fetch_array( $result ); echo $row['sum(itemQty)']; ?> you are missing a , after itemQty... your select should read mysql_query("SELECT itemQty, SUM(itemQty) AS TitemQty FROM transactions Where itemDescription= 'raffle'") or die (mysql_error()); notice that I also added an alias for the aggregate function... it will allow you to change this line echo $row['sum(itemQty)']; for the more simple echo $row['TitemQty']; Ahhhh.. Absolutely. That works.. Thanks Guys for the tutorial! Quote Link to comment https://forums.phpfreaks.com/topic/212924-unexpected-t_string-in-this-short-query/#findComment-1109024 Share on other sites More sharing options...
fortnox007 Posted September 9, 2010 Share Posted September 9, 2010 notice that I also added an alias for the aggregate function... it will allow you to change this line very smart : ) @vox, : ) always happy to help Quote Link to comment https://forums.phpfreaks.com/topic/212924-unexpected-t_string-in-this-short-query/#findComment-1109028 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.