Jump to content

string help


dannybrazil

Recommended Posts

Hello

I need help, I guess Im doing something wrong

 

I have an array of strings :

 

*it will be like that cus i will have to use 2 languages

 

$type["1"]="London";

$type["2"]="New York";

etc...

 

now when someone is searching for a city it gets the number from the database

 

$city="1"; (for example)

 

then I want to print the city's name:

 

<?

 

echo  '  $type["$city"]        ';

 

?>

 

and it doesnt work

 

well I know its not the real way....but Im trying

 

any help ?

 

 

Link to comment
https://forums.phpfreaks.com/topic/194497-string-help/
Share on other sites

echo  '   $type["$city"]        ';

 

Variables inside of single-quotes are not parsed and replaced by their actual value (i.e. the initial and final single-quotes.). Also, if the only thing inside of a string is a variable, no need for any quotes (i.e. the double-quotes around $city.)

 

echo $type[$city];

Link to comment
https://forums.phpfreaks.com/topic/194497-string-help/#findComment-1022982
Share on other sites

The 'code' you just posted does not have any php tags around the lines setting $type and produces this output -

 

$type["1"]="London"; $type["2"]="New York";

Notice: Undefined variable: type in your_file.php on line 9

 

If you put php tags around the php code, it works as expected and produces -

 

London
Link to comment
https://forums.phpfreaks.com/topic/194497-string-help/#findComment-1022997
Share on other sites

there is my real code


	     while($row = mysql_fetch_array($result))
	{	
	$id=$row['id'];
	$t=$row['type']';

	//TYPE
$type["1"] = "דירה";
$type["2"] = "דירת גג";
$type["3"] = "לופט";
$type["4"] = "דירת גן";
$type["5"] = "דירת סטודיו";
$type["6"] = "דו משפחתי";
$type["7"] = "בית פרטי";
$type["8"] = "פנטהאוז";
$type["9"] = "דופלקס";
$type["10"] = "טריפלקס";
$type["11"] = "וילה";
$type["12"] = "קוטג";
$type["13"] = "קראוון";
$type["14"] = "יחידת דיור";
$type["15"] = "מגרש למגורים";
$type["16"] = "משק חקלאי";




echo '<table border="0" width="800px" style="direction:rtl; margin-left:auto; margin-right:auto; background-color:#0188A6; margin-top:20px;text-align:right;">';

echo '<tr>';

echo '<td>';

$pic_1=$row['upload_1'];
echo '<a href="#" class="img_brdr" style=" float:right;"><img border="0" src="imgsize.php?h=100&img='.$pic_1.'"/></a>


<div style=" float:right; margin-right:20px; font-size:12px;">
	'.$type[$t].'
  </div>';


 

what I get no is ONLY THE FIRST LETTER of the string

 

any idea why ?

Link to comment
https://forums.phpfreaks.com/topic/194497-string-help/#findComment-1023003
Share on other sites

Since you have marked this as solved, I'll guess you found the problem, but the posted code cannot be your actual code because it has an extra single-quote that would cause a fatal parse error.

 

Once that problem was fixed, your code worked for me as expected.

Link to comment
https://forums.phpfreaks.com/topic/194497-string-help/#findComment-1023014
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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