Jump to content

[SOLVED] Need big help (URGENT!)


studgate

Recommended Posts

Hi Guys, I need some help, I have written a report page

but I am having problem loading the data from the database

here is the code, please help:

 

<?
$num = 0;
$dbconn = @mysql_connect("localhost","username","password");
@mysql_select_db("database");

if (empty($bywhat))
{
?>
	<font size="+2"><strong>Report Page</strong></font><br><br>
   Links:<br>
	 <br>
	     <a href="reports.php?bywhat=date">Report by date</a><br>
	     <a href="reports.php?bywhat=state">Report by state</a><br>
	     <a href="reports.php?bywhat=city">Report by city</a><br>
	     <a href="reports.php?bywhat=situation">Report by activity</a><br>
	<br>

	<a href="form.php">Form Page</a>		
<?
}
else
{
	$strsql = "SELECT ".$bywhat." , COUNT(*) as num FROM database ORDER BY ".$bywhat." DESC";
	$ressql = @mysql_query($strsql);
?>
<table class="sort-table" id="table-1" cellspacing="0">
<thead> 
	<tr>
		<td align="left" width="300"> <? if ($bywhat=='date') echo("Date"); elseif ($bywhat=='city') echo("City"); elseif ($bywhat=='situation') echo("Situation"); elseif ($bywhat=='state') echo("State"); ?></td>
		<td align="right" width="100"> Number. </td>
	</tr>
  </thead>
	<tbody>
<?
	while(list($subj, $num)=@mysql_fetch_row($ressql))
	{
	 if(strlen($subj)<1){
		continue;
	}
	$count++;
	if($count%2!=0){
		$class="<tr class=\"odd\">";
	}else{
		$class="<tr class=\"even\">";
	}

	echo "$class";
?>

  <td align="left"> <a href="results.php?subj=<?=$subj?>&bywhat=<?=$bywhat?>"><?=$subj?></a></td>
			<td align="right"> <?=$num?> </td>
		</tr>

<?
	}
	@mysql_free_result($ressql);
?>
</tbody>
</table>

<?
}
@mysql_close($dbconn);
?>

 

I can't find the problem, any help is welcome.

Thanks!

Link to comment
Share on other sites

The first thing to do is replace

 

	$dbconn = @mysql_connect("localhost","username","password");
@mysql_select_db("database");

 

with

 

	$dbconn = mysql_connect("localhost","username","password") or die("Couldn't connect to database\n");
mysql_select_db("database") or die("Couldn't select database\n");

 

Similarly with every call to mysql_query().  You should add 'or die("Query failed: " . mysql_error());' to each one.  But DON'T add it to mysql_num_rows(), or mysql_fetch_row() or any of the result fetching functions.

 

@ will ignore errors.  die() will tell you when there is an error.

Link to comment
Share on other sites

btherl, thank you very much, I found the problem.

that's why I love this site.

I completely forgot to put the

	
$ressql = mysql_query($strsql) or die("Error in $strsql\n" . mysql_error());

and I was able to find the problem and solved the issue.

Thank you again.

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.