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 Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/ 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. Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528401 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 Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528409 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()); Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528410 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 Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528411 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 Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528413 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()); } Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528415 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. Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528417 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. Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528421 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 Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528424 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 } Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528426 Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 Ooookay, so whats the error? =/ Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528428 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"); ?> Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528429 Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 query success Now what? Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528450 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"); ?> Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528452 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 Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528454 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. Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528457 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 Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528460 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. Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528462 Share on other sites More sharing options...
Monk3h Posted April 27, 2008 Author Share Posted April 27, 2008 id, owner, log, unread Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528464 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 Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528483 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 Link to comment https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.