Jump to content

1 = 5 ??????


atongraaff

Recommended Posts

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>

Link to comment
Share on other sites

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??

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 !

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.