Jump to content

Sub Strings


jrodd32

Recommended Posts

to get a logical value, you'd have to run a comparison of some sort. substr() actually returns a string:
[code]
<?php
if (substr(49,1) == 'T') {
  // 49th position is 'T'
}
?>
[/code]

it would be the same idea in mysql - the function returns a string, so you would then have to compare that value to something to get a logical return.
Link to comment
Share on other sites

function init_officials($sport)
{
  if (!($db = @mysql_connect('localhost', 'username','password')))
  {;
    print 'Temporarily unable to connect to database server. Please try again later.';
    exit;
  }
  mysql_select_db('Scoreboard',$db);
  global $officials;
  $officials=mysql_fetch_array(mysql_query("SELECT officials_complete.* FROM officials_complete where CURRENT=\"TRUE\""));
  global $officialslist;
  $officialslist=mysql_query("IF $sport1==\"T\") THEN SELECT lname, fname, address, city, st, zip, zip4, homephone, workphone, email FROM officials_complete WHERE CURRENT=\"TRUE\" ORDER by lname");
  print mysql_error();
}

Originally the $sport will come in as a variable within the database that I have assigned through a drop down list of options.
EX.) BA or BK or FB

This is to allow me to be able to sort the officials by which sports they are qualified to work. 
In the database the variables BA or BK etc. are strings which are 50 places long.
If the last place in the string is a 'T' then the official is cleared to work.
When, I echo $sport, after the mysql_query of the database it still returns as BA,etc.
Thus, when I try:
$sport1=substr($sport,49,1);
and echo $sport1;
I get BA9.
There is not a single 9 within the database.

What does this mean?
Link to comment
Share on other sites

you've hit an overflow somehow. if you're simply trying to see whether or not the last character of a string is a 'T' or not, just use the '-1' of substring to pull that character:
[code]
<?php
$string = 'BA';
echo substr($string, -1); // echos 'A'

$string = 'BASDJIBKEMS<>MBOSJEM';
echo substr($string, -1); // echos 'M'
?>
[/code]
Link to comment
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.