Jump to content

That's just weird!


jandrews3

Recommended Posts

Why would the following code give the following output?!? That's just weird!

 

Code:

<?php
$query_g = "SELECT name, title, member_no, email FROM ithf_groups WHERE title = '$title'";
$result_g= mysql_query($query_g) or die ("Could not perform query: ".mysql_error());

while ($row_g = mysql_fetch_array($result_g)){
   print $query_g['id']."-".$query_g['name']."-".$query_g['member_no']."-".$query_g['email']."<br>";
}

php?>

 

OUTPUT:

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

S-S-S-S

 

 

DATABASE TABLE CONTAINS VALID DATA FOR EACH OF THESE FIELDS:

 

Link to comment
https://forums.phpfreaks.com/topic/127320-thats-just-weird/
Share on other sites

Also one little thing on your while loop:

 

while ($row_g = mysql_fetch_array($result_g)){

//...

}

 

You should add two = signs next to $row_g, because there are checking if something is true. Using only one = is to asign variables.

 

Sometimes that causes some small bugs in your scripts that can be a royal pain to debug, so you should try to use one = you ASSIGN variables, and two = when you COMPARE them. :)

Link to comment
https://forums.phpfreaks.com/topic/127320-thats-just-weird/#findComment-658591
Share on other sites

Also one little thing on your while loop:

 

while ($row_g = mysql_fetch_array($result_g)){

//...

}

 

You should add two = signs next to $row_g, because there are checking if something is true. Using only one = is to asign variables.

 

Sometimes that causes some small bugs in your scripts that can be a royal pain to debug, so you should try to use one = you ASSIGN variables, and two = when you COMPARE them. :)

 

He isn't trying to compare them. He is trying to set them while looping through the database tables.

 

OP you should try this:

<?php
$query_g = "SELECT id, name, title, member_no, email FROM ithf_groups WHERE title = '$title'";
$result_g= mysql_query($query_g) or die ("Could not perform query: ".mysql_error());

while ($row_g = mysql_fetch_array($result_g)){
   print $row_g['id']."-".$row_g['name']."-".$row_g['member_no']."-".$row_g['email']."<br>";
}

php?>

Link to comment
https://forums.phpfreaks.com/topic/127320-thats-just-weird/#findComment-658593
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.