jrodd32 Posted September 18, 2006 Share Posted September 18, 2006 in php if my code was:substr(\"T\",49,1);would that return a logical value T or F if the letter T was in the 49th position of the string with the one representing the number of values you want printed.If so, is the syntax in mysql the same? Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 18, 2006 Share Posted September 18, 2006 to get a logical value, you'd have to run a comparison of some sort. substr() actually returns a string:[code]<?phpif (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. Quote Link to comment Share on other sites More sharing options...
jrodd32 Posted September 18, 2006 Author Share Posted September 18, 2006 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 FBThis 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? Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 19, 2006 Share Posted September 19, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.