studgate Posted February 28, 2007 Share Posted February 28, 2007 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 https://forums.phpfreaks.com/topic/40445-solved-need-big-help-urgent/ Share on other sites More sharing options...
btherl Posted February 28, 2007 Share Posted February 28, 2007 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 https://forums.phpfreaks.com/topic/40445-solved-need-big-help-urgent/#findComment-195709 Share on other sites More sharing options...
btherl Posted February 28, 2007 Share Posted February 28, 2007 Example: $strsql = "SELECT ".$bywhat." , COUNT(*) as num FROM database ORDER BY ".$bywhat." DESC"; $ressql = mysql_query($strsql) or die("Error in $strsql\n" . mysql_error()); Link to comment https://forums.phpfreaks.com/topic/40445-solved-need-big-help-urgent/#findComment-195711 Share on other sites More sharing options...
studgate Posted February 28, 2007 Author Share Posted February 28, 2007 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 https://forums.phpfreaks.com/topic/40445-solved-need-big-help-urgent/#findComment-195737 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.