atongraaff Posted January 16, 2019 Share Posted January 16, 2019 (edited) hi, after 8 hours i give up and ask for help as i have no idea why the if operator keep telling 1 = the same as 5. i changed the = to == and === It keeps telling that if($regel==$max) { ... } is always true it has always worked but not in this part. what i try to accomplish is simple, in my table i want max 5 results row then start a new row. <table id="cust" style="border: 1px solid black; border-collapse: collapse; width: 800px;" > <tr style="border: 1px solid black;"> <?php $regel = 1; $max = 5; $query = "SELECT * from customer where Costcenter = '$item' ORDER by Client"; $customerresult = mysqli_query($conn, $query) or die(mysqli_error($conn)); if (!$customerresult) printf("Query failed: %s\n", $mysqli->error); while ($customerrow = $customerresult->fetch_array()) { ?> <td style="border: 1px solid black;"><?php echo $regel ;?> <?php echo $customerrow['Client']; ?> </td> <?php $regel = $regel++ ; if($regel == $max) { echo "</tr><tr>"; $regel = 1; } } ?> </tr> </table> Edited January 16, 2019 by atongraaff better explenation Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 16, 2019 Share Posted January 16, 2019 So hard to read your code. Look at this way of writing it: echo "<table id='cust' style='border: 1px solid black; border-collapse: collapse; width: 800px;'> <tr style='border: 1px solid black;'>"; $regel = 1; $max = 5; $query = "SELECT * from customer where Costcenter = '$item' ORDER by Client"; $customerresult = mysqli_query($conn, $query) or die(mysqli_error($conn)); if (!$customerresult) { echo "Query failed. Message is: " . $mysqli->error; exit(); } while ($customerrow = $customerresult->fetch_array()) { echo "<td style='border: 1px solid black;'>" . $regel . " " . $customerrow['Client'] . "</td>"; $regel++; if($regel == $max) { echo "</tr><tr>"; $regel = 1; } } echo "</tr> </table>"; The change of your line: $regel = $regel++; to what I used may be a difference. Don't know, but nothing else seemed out of place. BTW - do you have php error checking turned on?? Quote Link to comment Share on other sites More sharing options...
atongraaff Posted January 16, 2019 Author Share Posted January 16, 2019 yes, i have both lines at the top of my code. indeed this way of coding is better readeble, maybe i schould ditch phpdesigner as it gives me a lot of bad formatting as well. even when i changed to your code the same happens, it keeps telling $regel is 5 on every output. Quote Link to comment Share on other sites More sharing options...
Barand Posted January 16, 2019 Share Posted January 16, 2019 Don't use "SELECT * ". You only want the client column so why select everything. Use "SELECT client FROM ...." If you use "or die()", how do you expect the next line to execute? Quote Link to comment Share on other sites More sharing options...
atongraaff Posted January 16, 2019 Author Share Posted January 16, 2019 Weird, i decided to edit the same code with notepad++ and suddenly some other characters popped up in the script. Clearly phpdesigner is making issues. I am sorry for the inconvinience as after removing the garbage with notepad++ the code was working correct ! Quote Link to comment Share on other sites More sharing options...
atongraaff Posted January 16, 2019 Author Share Posted January 16, 2019 3 minutes ago, Barand said: Don't use "SELECT * ". You only want the client column so why select everything. Use "SELECT client FROM ...." If you use "or die()", how do you expect the next line to execute? You are right making unneeded memoory filling up there, and die closes the script so will never get a message. Changed that. Quote Link to comment Share on other sites More sharing options...
Barand Posted January 16, 2019 Share Posted January 16, 2019 Before you connect to mysqli, call mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); mysqli will now automatically throw errors without you having to keep checking if it worked or not. It saves a lot of coding. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 16, 2019 Share Posted January 16, 2019 Do you mean to say that you never see a value for 'regel' of 1, 2, 3, 4 ? Quote Link to comment Share on other sites More sharing options...
atongraaff Posted January 16, 2019 Author Share Posted January 16, 2019 1 hour ago, Barand said: Don't use "SELECT * ". You only want the client column so why select everything. Use "SELECT client FROM ...." If you use "or die()", how do you expect the next line to execute? You are right making unneeded memoory filling up there, and die closes the script so will never get a message. Changed that. the problem is solved, i used $regel = $regel++; by replacing that with just : $regel++ ; It is working as should. Thank everybody for the other hints to code better. 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.