getting query results from mysql

$con = new mysqli("localhost","root","","maroonboxdb");

if ($con->connect_error) die ($con->connect_error);
{
echo "Failed to connect to MYSQL: " . mysql_connect_error();
}
//Perform Queries
$actress_query = “SELECT firstname, lastname, date_of_birth FROM actors WHERE gender LIKE ‘Female’”;

$result = $con->query($actress_query);

if (!$result)die ($con->error);

$rows = $result->num_rows;

for ($j = 0; $j < $rows; ++$j)
{
	$result->data_seek($j);
	$row = $result->fetch_array(MYSQL_BOTH);
	echo $row['firstname'].' ';
	echo $row['lastname'].' ';
	echo $row['date_of_birth'].'<br>';

}

$result->close();

You’re not giving is enough information to help you. What is it doing, what should it be doing?

I will assume this is for a class project. It is silly to use a FOR clause to loop thru records. You should use
the WHILE instead… Either way, here is a page that explains how to display data from a database. You
can press the PREVIOUS or NEXT-CHAPTER to look at other samples. And, on the left is just about anything
you might need to look up. So, once you read these and redo your code, let us know what does not work
and maybe we can help. Good luck…

http://www.w3schools.com/php/php_mysql_select.asp

Sponsor our Newsletter | Privacy Policy | Terms of Service