Jump to content
Larry Ullman's Book Forums
Sign in to follow this  

Recommended Posts

On line 33 it reads:

 

$words = FALSE; // Flag variable

 

- Why is this needed? Why false boolean?

 

 

On line 37 it reads:

 

$r = msyqli_query($dbc, $q);

 

if (mysqli_num_rows($r) == 1) {

 

$words = mysqli_fetch_array($r, MYSQLI_ASSOC);

 

}

 

- Is this common practice, to check to see if there is at least one result returned from the query? In some scripts, this is included and then in some it is. For example go to line 47 of the same script, when the array is fetched the function isn't wrapped in the same way as above.

 

 

Line 46, 47:

 

$r = msyqli_query($dbc, $q);

 

$r = mysqli_fetch_array($r, MYSQLI_ASSOC);

Share this post


Link to post
Share on other sites

Well the database has to check there is at least one record to process the next section. You have to check for something otherwise how can you process next section of script

Share this post


Link to post
Share on other sites

hmm makes sense Edward

 

if (mysqli_num_rows($r) == 1) {

 

it would be a good idea to always wrap the fetch function inside of this conditional block. I have some scripts that don't have this, looks like I'll be looking to modify those now.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...