shadowpat Posted May 17, 2013 Share Posted May 17, 2013 (edited) Hello, For the past day I have been trying to echo all of a mysqli table. Although I keep getting tons of errors. Right now my code is: $result = mysqli_query($connection,"SELECT * FROM ".$myusername."-mail ORDER BY date ASC"); while($row = mysqli_fetch_array($result)) { echo "done"; echo "<br>"; } Right now I get this error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /hermes/bosoraweb172/b2121/ipg.unityinvtorg/main.php on line 63 line 63 is the "while" line that i posted here..... Thank you so much! Patrick Edited May 17, 2013 by shadowpat Quote Link to comment Share on other sites More sharing options...
dalecosp Posted May 17, 2013 Share Posted May 17, 2013 (edited) mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given Check for $result before you call mysqli_fetch_array. It's apparently returning false. $result = mysqli_query($connection,"SELECT * FROM ".$myusername."-mail ORDER BY date ASC"); if ($result) { while($row = mysqli_fetch_array($result)) { echo "done"; echo "<br>"; } } else { echo "Oh noes, an error!"; } Edited May 17, 2013 by dalecosp Quote Link to comment Share on other sites More sharing options...
shadowpat Posted May 17, 2013 Author Share Posted May 17, 2013 (edited) Thanks for the speedy reply! Now i get this error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in /hermes/bosoraweb172/b2121/ipg.unityinvtorg/main.php on line 63 again line 63 is the "while" line thanks! Edited May 17, 2013 by shadowpat Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 17, 2013 Share Posted May 17, 2013 Read the post in my signature on debugging sql Quote Link to comment Share on other sites More sharing options...
dalecosp Posted May 17, 2013 Share Posted May 17, 2013 And, actually, you'll probably want something besides "Oh noes, an error!" --- either debugging information (if you're in development), or a proper error handling routine if not. Quote Link to comment Share on other sites More sharing options...
dalecosp Posted May 17, 2013 Share Posted May 17, 2013 (edited) Re-read my first post, it's been edited ... I flew off the handle a bit too soon, and that would cause the second error. Edited May 17, 2013 by dalecosp Quote Link to comment Share on other sites More sharing options...
shadowpat Posted May 17, 2013 Author Share Posted May 17, 2013 (edited) @Jessica: ok now i have $result = mysqli_query($connection,"SELECT * FROM ".$myusername."-mail ORDER BY date ASC") or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error(), E_USER_ERROR); while($row=mysqli_fetch_array($connection,$result)) { echo "done"; echo "<br>"; } and get this error: Warning: mysqli_error() expects exactly 1 parameter, 0 given in /hermes/bosoraweb172/b2121/ipg.unityinvtorg/main.php on line 61 Fatal error: Query Failed! SQL: - Error: in /hermes/bosoraweb172/b2121/ipg.unityinvtorg/main.php on line 61 Edited May 17, 2013 by shadowpat Quote Link to comment Share on other sites More sharing options...
shadowpat Posted May 17, 2013 Author Share Posted May 17, 2013 Re-read my first post, it's been edited ... I flew off the handle a bit too soon, and that would cause the second error. now i get "oh noes, an error" with your code Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 17, 2013 Share Posted May 17, 2013 try echoing your query to make sure it contains what you expect it to contain Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 17, 2013 Share Posted May 17, 2013 I think you need some basic lessons on programming. You can't just copy and paste code into yours and expect it to work. Quote Link to comment Share on other sites More sharing options...
shadowpat Posted May 17, 2013 Author Share Posted May 17, 2013 (edited) try echoing your query to make sure it contains what you expect it to contain Thanks. This does not solve the problem, or give me any info..... here is my code now: $result = mysqli_query($connection,"SELECT * FROM ".$myusername."-mail ORDER BY date ASC"); echo "The \$result variable contains: ".$result; echo "<br/>"; if ($result) { while($row = mysqli_fetch_array($result)) { echo "done"; echo "<br>"; } } else { echo "Oh noes, an error!"; } when i do echo "The \$result variable contains: ".$result; all i get is The $result Variable is: That is all..... please help Edited May 17, 2013 by shadowpat Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 17, 2013 Share Posted May 17, 2013 the current error is because mysqli_error( ... ) requires the mysqli connection resource as a parameter. Quote Link to comment Share on other sites More sharing options...
shadowpat Posted May 17, 2013 Author Share Posted May 17, 2013 (edited) I think you need some basic lessons on programming. You can't just copy and paste code into yours and expect it to work. That isn't what I was doing at first.... I used my own code from a mysql table, and changed it over to mysqli.... but since that didnt really work i kind of had to copy some other code..... i do know how to program you know. How well could you program in PHP or even MYSQLI when you were 13? Edited May 17, 2013 by shadowpat Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 17, 2013 Share Posted May 17, 2013 $query = "SELECT * FROM " . $myusername . "-mail ORDER BY date ASC"; echo $query; Quote Link to comment Share on other sites More sharing options...
shadowpat Posted May 17, 2013 Author Share Posted May 17, 2013 the current error is because mysqli_error( ... ) requires the mysqli connection resource as a parameter. Here is my code now... i get a new error with more info: $result = mysqli_query($connection,"SELECT * FROM ".$myusername."-mail ORDER BY date ASC"); echo "The \$result variable contains: ".$result; echo "<br/>"; if ($result) { while($row = mysqli_fetch_array($result)) { echo "done"; echo "<br>"; } } else { echo "Error message".mysqli_error($connection); } Now i get an error telling me that there is an error near -mail. There is a variable near -mail.... maybe that is the cause of the error? Quote Link to comment Share on other sites More sharing options...
shadowpat Posted May 17, 2013 Author Share Posted May 17, 2013 $query = "SELECT * FROM " . $myusername . "-mail ORDER BY date ASC"; echo $query; Thx, no error there though... it echos: SELECT * FROM mailtest-mail ORDER BY date ASC that is what i expected it to say Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 17, 2013 Share Posted May 17, 2013 Show us your db connection sans username and password Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 17, 2013 Share Posted May 17, 2013 (edited) the problem is that your table name contains a special character that makes it look like it's a subtraction problem. A) you should not use special characters in a table/column name unless you know how you would make it work with that special character in the name. B) you should NOT make a separate table for each user. Edited May 17, 2013 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Solution jcbones Posted May 17, 2013 Solution Share Posted May 17, 2013 This is similar to where you should be, taking all the info out of a database, and dumping it back to the screen: commented up <?php include('connection.php'); //make sure you have a mysqli connection. $sql = "SELECT * FROM `{$myusername}-mail` ORDER BY date ASC"; //define your sql statement. $result = mysqli_query($connection,$sql) or trigger_error($sql . ' - has encountered an error at:<br />' . mysqli_error($connection)); //call the sql statement, if it errors give us de-bugging info. $fields = mysqli_fetch_fields($connection); //get your field list. $field_count = mysqli_num_fields($connection); //get the number of fields. echo '<table>' . "\n" . '<tr>'; //start a table. $i = 0; //define a counter. foreach($fields as $field) { //for each field if(++$i == 1) { //if this is the first run of the foreach statemnt. echo '<th colspan="' . $field_count . '">' . $field->table . '</th></tr><tr>'; //print out a table header with the table name. } echo "\n" . '<th>' . $field-name . '</th>'; //print the column name at the top of each column. } echo '</tr>'; //ends the column row. while($row = mysqli_fetch_row($result)) { //while you still have data left in the table: echo '<tr><td>' . implode('</td><td>' , $row) . '</td></tr>'; //dump it all into a row, matching the data to the correct column. } echo '</table>'; //ends the table. Sometimes it helps to just see it, with comments to follow what it is doing. Quote Link to comment Share on other sites More sharing options...
dalecosp Posted May 17, 2013 Share Posted May 17, 2013 the problem is that your table name contains a special character that makes it look like it's a subtraction problem. A) you should not use special characters in a table/column name unless you know how you would make it work with that special character in the name. B) you should NOT make a separate table for each user. +1. Explain your data and perhaps someone can give you a good layout for a real *relational* database. Having a table for every user is a big no-no. Quote Link to comment Share on other sites More sharing options...
shadowpat Posted May 17, 2013 Author Share Posted May 17, 2013 Show us your db connection sans username and password you really think im that stupid? I am NOT showing my password, or even my host Quote Link to comment Share on other sites More sharing options...
shadowpat Posted May 17, 2013 Author Share Posted May 17, 2013 This is similar to where you should be, taking all the info out of a database, and dumping it back to the screen: commented up <?php include('connection.php'); //make sure you have a mysqli connection. $sql = "SELECT * FROM `{$myusername}-mail` ORDER BY date ASC"; //define your sql statement. $result = mysqli_query($connection,$sql) or trigger_error($sql . ' - has encountered an error at:<br />' . mysqli_error($connection)); //call the sql statement, if it errors give us de-bugging info. $fields = mysqli_fetch_fields($connection); //get your field list. $field_count = mysqli_num_fields($connection); //get the number of fields. echo '<table>' . "\n" . '<tr>'; //start a table. $i = 0; //define a counter. foreach($fields as $field) { //for each field if(++$i == 1) { //if this is the first run of the foreach statemnt. echo '<th colspan="' . $field_count . '">' . $field->table . '</th></tr><tr>'; //print out a table header with the table name. } echo "\n" . '<th>' . $field-name . '</th>'; //print the column name at the top of each column. } echo '</tr>'; //ends the column row. while($row = mysqli_fetch_row($result)) { //while you still have data left in the table: echo '<tr><td>' . implode('</td><td>' , $row) . '</td></tr>'; //dump it all into a row, matching the data to the correct column. } echo '</table>'; //ends the table. Sometimes it helps to just see it, with comments to follow what it is doing. thanks i will try that soon... stay posted Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 17, 2013 Share Posted May 17, 2013 sans means without. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 17, 2013 Share Posted May 17, 2013 you really think im that stupid? I am NOT showing my password, or even my hostSays the person who doesn't know what "sans" means... The irony Quote Link to comment Share on other sites More sharing options...
shadowpat Posted May 19, 2013 Author Share Posted May 19, 2013 This is similar to where you should be, taking all the info out of a database, and dumping it back to the screen: commented up <?php include('connection.php'); //make sure you have a mysqli connection. $sql = "SELECT * FROM `{$myusername}-mail` ORDER BY date ASC"; //define your sql statement. $result = mysqli_query($connection,$sql) or trigger_error($sql . ' - has encountered an error at:<br />' . mysqli_error($connection)); //call the sql statement, if it errors give us de-bugging info. $fields = mysqli_fetch_fields($connection); //get your field list. $field_count = mysqli_num_fields($connection); //get the number of fields. echo '<table>' . "\n" . '<tr>'; //start a table. $i = 0; //define a counter. foreach($fields as $field) { //for each field if(++$i == 1) { //if this is the first run of the foreach statemnt. echo '<th colspan="' . $field_count . '">' . $field->table . '</th></tr><tr>'; //print out a table header with the table name. } echo "\n" . '<th>' . $field-name . '</th>'; //print the column name at the top of each column. } echo '</tr>'; //ends the column row. while($row = mysqli_fetch_row($result)) { //while you still have data left in the table: echo '<tr><td>' . implode('</td><td>' , $row) . '</td></tr>'; //dump it all into a row, matching the data to the correct column. } echo '</table>'; //ends the table. Sometimes it helps to just see it, with comments to follow what it is doing. YAY! that solved it! That code had a few errors, but I changed a few things and got it working. Thanks allot! Also, the tables didnt work... i will post a new question to see if anybody can get it to work. thanks! 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.