Jump to content

PHP & MySQL


bravo14

Recommended Posts

Hi folks

 

Newbie to this forum, but hoping there is someone there who can help

 

I am trying to display the results of a MySQL query on a page using PHP, the query works in phpmyadmin

 

see code below

 

<?php

$con = mysql_connect('213.171.219.88', 'yardleyheroes', 'heroes', true);

if(!$con)

{

      die('Could not connect: ' . mysql_error());

}

mysql_select_db('yardleyheroes', $con);

$result = mysql_query('SELECT Sum(fines.fine_amount) AS SumOffine_amount, profiles.name FROM fines INNER JOIN profiles ON fines.profile_id = profiles.profile_id GROUP BY profiles.name ORDER BY Sum(fines.fine_amount); LIMIT 0, 30 ', $con);

if(mysql_num_rows($result) < 1)

{

  echo('<tr><td colspan="2">Sorry, no results were found.</td></tr>');

}

else

{

  while($row = mysql_fetch_array($result))

  {

      echo('<tr><td valign="top">' . $row['name'] . '</td>');

      echo('<td> £' . $row['SumOffine_amount'] .'.00</td></tr>');

  }

}

mysql_close($con);

?>

 

I get the following message on the page

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/fhlinux147/y/yardleyheroes.co.uk/user/htdocs/fines.php on line 52

 

Line 52 is if(mysql_num_rows($result) < 1)

 

Any ideas, the page can be seen at www.yardleyheroes.co.uk/fines.php

Link to comment
https://forums.phpfreaks.com/topic/109172-php-mysql/
Share on other sites

That would meant that your query is failing. Try this:

 

$result = mysql_query('SELECT Sum(fines.fine_amount) AS SumOffine_amount, profiles.name FROM fines INNER JOIN profiles ON fines.profile_id = profiles.profile_id GROUP BY profiles.name ORDER BY Sum(fines.fine_amount); LIMIT 0, 30 ', $con) or die(mysql_error());

 

Also, next time please put


tags around your code.

 

P.S. Welcome to the forum

Link to comment
https://forums.phpfreaks.com/topic/109172-php-mysql/#findComment-560037
Share on other sites

So I have a mysql database that is working and can display the results correctly. My next step is after it prints the "state" array in the code below for each result I want it to create a button or a link to display the full information of that record. I could make each record a separate link and page but I would rather be able to have it pass information based on the link clicked to a single page that can pull the information . Not sure exactly how to go about this or where to start looking. 

 

 

if($results)
{
while($array= mysql_fetch_assoc($results)){
	echo '<br>';
	print $array['School Name'];
	echo "     ";
	print $array['City'];
	echo ",";
	print $array['State'];
	echo "     ";
}
}

Link to comment
https://forums.phpfreaks.com/topic/109172-php-mysql/#findComment-560245
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.