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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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