smarthouseguy Posted January 18, 2007 Share Posted January 18, 2007 I am getting the following error, not sure what I need to do to fix this... [quote]Warning: mysql_fetch_array(): 6 is not a valid MySQL result resource in /usr/local/apache2/htdocs/homepbx/kevin/home/cdr.php on line 23[/quote][code]<?php$connection=mysql_connect("host","db","pass");if (!$connection) {echo "Could not connect to MySql server!";exit;}$db=mysql_select_db("asterisk",$connection);if (!$db) {echo "Could not select database";exit;}$sql = 'SELECT * FROM `table`';$mysql_result=mysql_query($sql,$connection);$num_rows=mysql_num_rows($mysql_result);if ($num_rows == 0) {echo "Sorry, we have no records";} else {echo "<div align=\"center\"><table summary=\"HomePBX Call Detail Records\" cellspacing=\"0\" cellpadding=\"0\"><caption>$name's Call Detail Records</caption>";echo "<tr><th class=\"title\">Call Date</th><th>Caller ID</th><th>Source</th><th>Destination</th><th>Duration</th></tr>";while ($row=mysql_fetch_array($mysql_result)) {$result=$mysql_result;$id=$row["calldate"];$var_1=$row["clid"];$var_2=$row["src"];$var_3=$row["dst"];$var_4=$row["duration"];$i = 0;while (($row=mysql_fetch_row($result)) !== false) { $i++; echo "<tr class=\"d".($i & 1)."\">"; echo "<td>".$row[0]."</td>"; echo "<td>".$row[1]."</td>"; echo "<td>".$row[2]."</td>"; echo "<td>".$row[3]."</td>"; echo "<td>".$row[4]."</td>"; echo "</tr>\n";}mysql_free_result($result);}}mysql_close($connection);?></table></div>[/code]is this because of double while statements???if I try to remove the [quote]while ($row=mysql_fetch_array($mysql_result)) {[/quote] I no longer get my data...all I am trying to accomplish with this right now is that the rows alternate color.. this is working, except for the error....Any help will be greatly appreciated.Kind Regards,Smarthouseguy Quote Link to comment Share on other sites More sharing options...
Cep Posted January 18, 2007 Share Posted January 18, 2007 You have stated somewhere in your code that the array as a sixth key and the error is telling you there is no sixth key to read from. Quote Link to comment Share on other sites More sharing options...
thedarkwinter Posted January 18, 2007 Share Posted January 18, 2007 Hiyou are using the same variable in both while loops...try using $arr = mysql_fetch_array in the first oneand $row = mysql_fetch_row in the second one.(or something)cheers,tdw Quote Link to comment Share on other sites More sharing options...
smarthouseguy Posted January 20, 2007 Author Share Posted January 20, 2007 I am a newbie to php... loving it so far.. this is what I did and it seems to work... if this is not correct please let me know... :-)[code]<?php$connection=mysql_connect("host","db","pass");if (!$connection) {echo "Could not connect to MySql server!";exit;}$db=mysql_select_db("asterisk",$connection);if (!$db) {echo "Could not select database";exit;}$sql = 'SELECT * FROM `table`';$mysql_result=mysql_query($sql,$connection);$num_rows=mysql_num_rows($mysql_result);if ($num_rows == 0) {echo "Sorry, we have no records";} else {echo "<div align=\"center\"><table summary=\"HomePBX Call Detail Records\" cellspacing=\"0\" cellpadding=\"0\"><caption>$name's Call Detail Records</caption>";echo "<tr><th class=\"title\">Call Date</th><th>Caller ID</th><th>Source</th><th>Destination</th><th>Duration</th></tr>";if ($row=mysql_fetch_array($mysql_result)) {$result=$mysql_result;$id=$row["calldate"];$var_1=$row["clid"];$var_2=$row["src"];$var_3=$row["dst"];$var_4=$row["duration"];$i = 0;while (($row=mysql_fetch_row($result)) !== false) { $i++; echo "<tr class=\"d".($i & 1)."\">"; echo "<td>".$row[0]."</td>"; echo "<td>".$row[1]."</td>"; echo "<td>".$row[2]."</td>"; echo "<td>".$row[3]."</td>"; echo "<td>".$row[4]."</td>"; echo "</tr>\n";}mysql_free_result($result);}}mysql_close($connection);?></table></div></body></html>[/code]it seems like changing the first while loop to an if statement works... my next steps for this are to:[quote]1) get $row[4] to divide by 60 so I can take secs and make them mins2) get $row[4] to sum for total mins and display above the table3) add sort capabilities to the table data4) have it split the data and make a new page after say 12 records and maybe an option to control how many records can be displayed5) have export capabilites that will: a) export data from the records with a date range b) a php script that will auto bill by every 30 days exporting something like a monthly bill.... i)email the results of the monthly bill in a pdf or some other nice format ii)add history links to previous month's data to the call detail record page[/quote]any ideas or direction will keep my frustration levels to a minimum... Kind regards Quote Link to comment Share on other sites More sharing options...
Crimpage Posted January 21, 2007 Share Posted January 21, 2007 Using the IF statement for the mysql_fetch_array command will pull the whole array of information, whereas using a while loop, will iterate through each row of the results. Using the while loop with the fetch_array, means there is no need for the fetch_row command. I would use:[code]<?php$i = 0;while ($row=mysql_fetch_array($mysql_result)) {$i++;$id=$row["calldate"];$clid=$row["clid"];$src=$row["src"];$dst=$row["dst"];$duration=$row["duration"]; echo "<tr class=\"d".($i & 1)."\">"; echo "<td>".$id."</td>"; echo "<td>".$clid."</td>"; echo "<td>".$src."</td>"; echo "<td>".$dst."</td>"; echo "<td>".$duration."</td>"; echo "</tr>\n";}?>[/code] Quote Link to comment Share on other sites More sharing options...
smarthouseguy Posted February 5, 2007 Author Share Posted February 5, 2007 Fantastic... works perfectly... thanks very much.... ;D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.