Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.