Monk3h Posted April 27, 2008 Share Posted April 27, 2008 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/monk3h/public_html/alog.php on line 16 What did i do wrong? :S $lsel = mysql_query("select * from alog where owner=Admin order by id desc limit 100"); while ($log = mysql_fetch_array($lsel)) { // Line 16 Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 27, 2008 Share Posted April 27, 2008 I'm guessing there's an error in your query. Try this instead. $lsel = mysql_query("select * from alog where owner=Admin order by id desc limit 100"); if($lsel){ while ($log = mysql_fetch_array($lsel)) { // Line 16 } }else{ die("Unable to connect to database. ".mysql_error()); } This should display the mysql error, or copy your query and put it in phpmyadmin to check for errors. Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 Are you sure the syntax of that is right? It dosnt look right, when i Inputted it it just threw errors back at me. :S Quote Link to comment Share on other sites More sharing options...
marcus Posted April 27, 2008 Share Posted April 27, 2008 You need quotes around strings in mysql queries $lsel = mysql_query("SELECT * FROM `alog` WHERE `owner`='Admin' ORDER BY id DESC LIMIT 100") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$lsel = mysql_query("select * from alog where owner=Admin order by id desc lim' at line 1 Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 After replacing the line to what you said i get Parse error: syntax error, unexpected T_STRING in /home/monk3h/public_html/alog.php on line 19 Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 27, 2008 Share Posted April 27, 2008 Try this: $lsel = mysql_query("SELECT * FROM `alog` WHERE `owner` = 'Admin' ORDER BY `id` DESC LIMIT 100"); if($lsel){ while ($log = mysql_fetch_array($lsel)) { // Line 16 } }else{ die("Unable to connect to database. ".mysql_error()); } Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 Parse error: syntax error, unexpected T_STRING in /home/monk3h/public_html/alog.php on line 19 <?php $title = "Admin Log"; include("header.php"); ?> <?php if ($stat[rank] != Admin) { print "You're not an admin."; include("footer.php"); exit; } ?> <img src=images/trash.gif align=right border=0>This is your event log. Clear the Log? <a href=log.php?action=clear>Yup</a><br><br> <table cellspacing=0> <?php $lsel = mysql_query("SELECT * FROM `alog` WHERE `owner` = 'Admin' ORDER BY `id` DESC LIMIT 100"); if($lsel){ while ($log = mysql_fetch_array($lsel)) { } }else{ die("Unable to connect to database. ".mysql_error()); } print "<tr onmouseover=\"this.style.backgroundColor='EDD5AB';\" onmouseout=\"this.style.backgroundColor=''; \"><td>$log[log]<br>"; if ($action == clear) { print ("Log Cleared!"); } ?> </table> <?php include("footer.php"); ?> Thats the entire script so far. Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 27, 2008 Share Posted April 27, 2008 Line 19 being the die statement? The if -> while -> else -> die looks correct to me. Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 Its the else. I dont understand why on the line above there is a { then on the line below there is }else{ Thats just {} isnt that pointless? :S Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 27, 2008 Share Posted April 27, 2008 It's for the while loop while {// do something here } Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 Ooookay, so whats the error? =/ Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 27, 2008 Share Posted April 27, 2008 Try taking out the while loop and see if the errors goes away <?php $title = "Admin Log"; include("header.php"); ?> <?php if ($stat[rank] != Admin) { print "You're not an admin."; include("footer.php"); exit; } ?> <img src=images/trash.gif align=right border=0>This is your event log. Clear the Log? <a href=log.php?action=clear>Yup</a><br><br> <table cellspacing=0> <?php $lsel = mysql_query("SELECT * FROM `alog` WHERE `owner` = 'Admin' ORDER BY `id` DESC LIMIT 100"); if($lsel){ echo "query success"; }else{ die("Unable to connect to database. ".mysql_error()); } print "<tr onmouseover=\"this.style.backgroundColor='EDD5AB';\" onmouseout=\"this.style.backgroundColor=''; \"><td>$log[log]<br>"; if ($action == clear) { print ("Log Cleared!"); } ?> </table> <?php include("footer.php"); ?> Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 query success Now what? Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 27, 2008 Share Posted April 27, 2008 Now you can use the data <?php $title = "Admin Log"; include("header.php"); ?> <?php if ($stat[rank] != Admin) { print "You're not an admin."; include("footer.php"); exit; } ?> <img src=images/trash.gif align=right border=0>This is your event log. Clear the Log? <a href=log.php?action=clear>Yup</a><br><br> <table cellspacing=0> <?php $lsel = mysql_query("SELECT * FROM `alog` WHERE `owner` = 'Admin' ORDER BY `id` DESC LIMIT 100"); if($lsel){ while($arr = mysql_fetch_assoc($lsel)){ extract($arr); echo "Any arr variables that now have been established via the extract method on the line above"; } }else{ die("Unable to connect to database. ".mysql_error()); } print "<tr onmouseover=\"this.style.backgroundColor='EDD5AB';\" onmouseout=\"this.style.backgroundColor=''; \"><td>$log[log]<br>"; if ($action == clear) { print ("Log Cleared!"); } ?> </table> <?php include("footer.php"); ?> Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 Any arr variables that now have been established via the extract method on the line above T I'm confused. :s Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 27, 2008 Share Posted April 27, 2008 Look at the code, in the line above the echo statement I have extract($arr); which creates a variable of all values from the query on a per row basis. So for example, if your query returns a field called "name" and you wanted to echo it you would simple echo $name because the extract($arr) created a variable for each extracted field. Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 But i want to Print the content of the alog table in order of ID :s Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 27, 2008 Share Posted April 27, 2008 Which is fine, you still can because the query specifies that. Give me the fields from the table and I'll show you what I mean. Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 id, owner, log, unread Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 27, 2008 Share Posted April 27, 2008 then this should do the trick: <?php $title = "Admin Log"; include("header.php"); ?> <?php if ($stat[rank] != Admin) { print "You're not an admin."; include("footer.php"); exit; } ?> <img src=images/trash.gif align=right border=0>This is your event log. Clear the Log? <a href=log.php?action=clear>Yup</a><br><br> <table cellspacing=0> <?php $lsel = mysql_query("SELECT * FROM `alog` WHERE `owner` = 'Admin' ORDER BY `id` DESC LIMIT 100"); if($lsel){ while($arr = mysql_fetch_assoc($lsel)){ extract($arr); echo "$id $owner $log $unread <br />"; } }else{ die("Unable to connect to database. ".mysql_error()); } print "<tr onmouseover=\"this.style.backgroundColor='EDD5AB';\" onmouseout=\"this.style.backgroundColor=''; \"><td>$log[log]<br>"; if ($action == clear) { print ("Log Cleared!"); } ?> </table> <?php include("footer.php"); ?> And then just do whatever you want with the data Quote Link to comment Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 Why does it post it in a vertical line? ID Owner Log Unread Instead of ID Owner Log Unread 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.