passing data and substr...HELP!!!!!!!!!!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
apek
Forum Commoner
Posts: 96
Joined: Tue Jan 06, 2004 11:19 pm
Location: Holiday Plaza Johor Bahru

passing data and substr...HELP!!!!!!!!!!!!

Post by apek »

i have a problem here..
i have a submit form...with textboxes and a combobox...
the combobox contains a list of ID's like A1,B1 and C1...
let say i select A1 and click submit...

then the second form appear...
FYI,at the earlier submit form,i did a substr function after select the A1...
i want to cut only the "A"...
the purpose is at the second page,the A from the substr,will be used...
the second page contains a combobox with list of ID's like A2,A3,B2,B3...
so,when i choose A1 from the submit page,the combobox at the second page will allow me to choose only IDs starting with A...and same with B1 or C1..

and i have problem at the second page..
the combobox has nothing to choose...
i wonder whats wrong...

how to do this?
i mean how to do a substr at the first page,and then use the cut item to compare it with the other item at the second page?

substr(let say A)-->post to 2nd page-->use the A to display records starting with A only

do u understand what i'm trying to do?
sorry for my bad english...
i'm trying to talk here...

pls help....
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post by fastfingertips »

You have many ways to do that; one possibility is to take what in that string to his first break. Other way is to convert the string to an array and to take first part (this is the easy way) for that you have to use something like this:


Code: Select all

<?php
$str = "Hello friend, you're
        looking          good today!";

$a   = str_word_count($str, 1);
$b   = str_word_count($str, 2);
$c   = str_word_count($str);

print_r($a);
print_r($b);
print $c;

//Output may look like:

Array
(
    [0] => Hello
    [1] => friend
    [2] => you're
    [3] => looking
    [4] => good
    [5] => today
)

?>
Here you will find the functions that you may need to solve this in other ways:
http://ro2.php.net/strings
User avatar
apek
Forum Commoner
Posts: 96
Joined: Tue Jan 06, 2004 11:19 pm
Location: Holiday Plaza Johor Bahru

....

Post by apek »

thanks for your reply fingertips....
but i wanna do substr to item taken from mysql...
heres my code snippet...

at the submit page..

Code: Select all

//----------------------------------------------------

	$query2 = "Select idMajor from ".$DBprefix." tPartMinor where idmajor <>'' group by idmajor order by idmajor";
	$mesin = mysql_query($query2);
			while ($dbq = mysql_fetch_array($mesin)) &#123;
			echo("<OPTION VALUE=$dbq&#1111;idMajor] selected>$dbq&#1111;idMajor]</option>\n");
			$ayam=$dbq&#1111;idMajor];
			$depan=substr("$ayam",0,1);
						&#125;
?>
          </select>
      </td>
    </tr>
  </table>
  <br><br>
  <center>

   <input type="hidden" name="ID" value="<?=$referNum?>">
   <input type="hidden" name="hariIni" value="<?=$datToday?>">
   <input type="hidden" name="front" value="<?=$depan?>">
at the second page..i use the cut item from the substr function earlier...

Code: Select all

$minor=@$HTTP_POST_VARS&#1111;"front"];
.
.
.
.
. <select name="idMinor" size="1">
          <option value="0">ID Minor</option>
        <?php
   //----------------------------------------------------
   //          Access Data From MySQL
   //          TABLE : tPartMinor
   //----------------------------------------------------
	$query2 = "Select LEFT('idMinor',0) from ".$DBprefix." tPartMinor where LEFT('idMinor',0)='$minor'";
	$result2 = mysql_query($query2);
			while ($dbq2 = mysql_fetch_array($result2)) &#123;
			echo("<OPTION VALUE=$dbq2&#1111;idMinor] selected>$dbq2&#1111;idMinor]</option>\n");
		&#125;
?>
    </select>
but it seems i failed to do that...
what is the problem?
how to fix my code?pls help!!!!!!!!!!!!
Post Reply