Jump to content

MySQL query print help

Go to solution Solved by mantylt,

@Hikaru12 follow your own topics.

I might be wrong, but you are selecting count(*) which is one result, integer, you don't need cycle for that.

$result = mysql_query("SELECT Count(*) FROM myanimes WHERE Status='To Watch'");$row = mysql_fetch_array($result);    echo $row[0];    
$result = mysql_query("SELECT Count(*) FROM myanimes WHERE Status='To Watch'");	while($row = mysql_fetch_array($result))	{	 echo "$row[Status]";  	}	

The above works fine in a SQL statement issued directly but when I try to print it it does not work claiming an "Undefined Index". Is it possibly because it's out of range?

 

Status is set as a VARCHAR field in the database. I've also tried mysql_fetch_row because it only returns back a single row but I get the same error.

 

If I try to print it directly it claims an array to string error which makes sense since PHP understands tables as associative arrays. 

 

NOTE: Yes, I am aware of the SQL injection. This is a low stakes program that will be loaded on a Raspberry Pi and will get updated in the future.

Link to comment
https://linustechtips.com/topic/384088-mysql-query-print-help/
Share on other sites

Link to post
Share on other sites

@Hikaru12 follow your own topics.

I might be wrong, but you are selecting count(*) which is one result, integer, you don't need cycle for that.

$result = mysql_query("SELECT Count(*) FROM myanimes WHERE Status='To Watch'");$row = mysql_fetch_array($result);    echo $row[0];    

I am sorry for my english.

Link to comment
https://linustechtips.com/topic/384088-mysql-query-print-help/#findComment-5185676
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×