genzedu777 Posted November 8, 2010 Share Posted November 8, 2010 Hi guys, Would like to check if I have done my INNER JOIN function correctly, as I have received and an error msg Warning: mysqli_error() expects exactly 1 parameter, 0 given in D:\inetpub\vhosts\111.com\httpdocs\111.com\registration3.php on line 598. Thanks <?php $dbc = mysqli_connect('localhost', '111', '111', '111') or die(mysqli_error()); $query = "SELECT sl.subject_level_id, sl.level_id, sl.subject_id, tl.name AS level_name, ts.name AS subject_name " . "FROM tutor_subject_level AS sl " . "INNER JOIN tutor_level AS tl USING (level_id) " . "INNER JOIN tutor_subject AS ts USING (subject_id) "; $sql = mysqli_query($dbc, $query); echo'<table><tr>'; // Start your table outside the loop... and your first row $count = 0; // Start your counter while($data = mysqli_fetch_array($sql)) { /* Check to see whether or not this is a *new* row If it is, then end the previous and start the next and restart the counter. */ if ($count % 5 == 0) { echo "</tr><tr>"; $count = 0; } echo '<td><input name="subject_level[]" type="checkbox" id="'.$data['subject_level_id'].'" value="'.$data['subject_level_id'].'"/>'; echo '<label for="'.$data['subject_name'].'">'.$data['subject_name'].'</label></td>'; $count++; //Increment the count } echo '</tr></table><br/><br/>'; //Close your last row and your table, outside the loop ?> Wilson Quote Link to comment Share on other sites More sharing options...
revraz Posted November 8, 2010 Share Posted November 8, 2010 Remove the "or die (mysqli_error()) here $dbc = mysqli_connect('localhost', '111', '111', '111') or die(mysqli_error()); See if that works. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 8, 2010 Share Posted November 8, 2010 Test to see if your connection is sucessful this way as well as your query error: <?php $link = mysqli_connect("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } if (!mysqli_query($link, "SET a=1")) { printf("Errormessage: %s\n", mysqli_error($link)); } /* close connection */ mysqli_close($link); ?> Quote Link to comment Share on other sites More sharing options...
genzedu777 Posted November 8, 2010 Author Share Posted November 8, 2010 Hi Revraz, I have amended my codes accordingly through your instructions. And I have received this error msg, Errormessage: Unknown system variable 'a' Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in D:\inetpub\vhosts\111.com\httpdocs\111\111.php on line 612 Line 612 is referred to the code which I have highlighted in blue. Do you have any idea what went wrong? <?php $dbc = mysqli_connect('localhost', '111', '111', '111'); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $query = "SELECT sl.subject_level_id, sl.level_id, sl.subject_id, tl.name AS level_name, ts.name AS subject_name " . "FROM tutor_subject_level AS sl " . "INNER JOIN tutor_level AS tl USING (level_id) " . "INNER JOIN tutor_subject AS ts USING (subject_id) "; $sql = mysqli_query($dbc, $query); /* check connection */ if (!mysqli_query($dbc, "SET a=1")) { printf("Errormessage: %s\n", mysqli_error($dbc)); } echo'<table><tr>'; // Start your table outside the loop... and your first row $count = 0; // Start your counter while($data = mysqli_fetch_array($sql)) { /* Check to see whether or not this is a *new* row If it is, then end the previous and start the next and restart the counter. */ if ($count % 5 == 0) { echo "</tr><tr>"; $count = 0; } echo '<td><input name="subject_level[]" type="checkbox" id="'.$data['subject_level_id'].'" value="'.$data['subject_level_id'].'"/>'; echo '<label for="'.$data['subject_name'].'">'.$data['subject_name'].'</label></td>'; $count++; //Increment the count } echo '</tr></table><br/><br/>'; //Close your last row and your table, outside the loop mysqli_close($dbc); ?> Quote Link to comment Share on other sites More sharing options...
gskurski Posted November 8, 2010 Share Posted November 8, 2010 This might not matter, but I thought the proper syntax for mysql_query was: $sql = "SELECT * FROM table"; $result = mysql_query($sql, $connection); You have the connection listed first and then then sql string. Perhaps that is causing a problem? Quote Link to comment Share on other sites More sharing options...
OldWest Posted November 8, 2010 Share Posted November 8, 2010 IGNORE my last post! Quote Link to comment Share on other sites More sharing options...
revraz Posted November 8, 2010 Share Posted November 8, 2010 He is using mysqli Did you echo $sql to make sure you are getting a result? Quote Link to comment Share on other sites More sharing options...
genzedu777 Posted November 8, 2010 Author Share Posted November 8, 2010 Hi revraz, How do I echo $sql? I have tried, but it doesn't work. From what you see, in terms of my INNER JOIN code, did I structure it correctly? Thanks <?php $query = "SELECT sl.subject_level_id, sl.level_id, sl.subject_id, tl.name AS level_name, ts.name AS subject_name " . "FROM tutor_subject_level AS sl " . "INNER JOIN tutor_level AS tl USING (level_id) " . "INNER JOIN tutor_subject AS ts USING (subject_id) "; $sql = mysqli_query($dbc, $query); echo '$sql'; ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 8, 2010 Share Posted November 8, 2010 The query looks fine. Put a die or exit after the echo so the code stops and you can see the value. And you want to use echo $sql; without single quotes. Single quotes prints the variable name, not it's contents. 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.