PHP assign concat value to variable [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
i want to concat two variable and assign it to another variable
$name = Drew;
$counter = $counter + 1;
$num_padded = sprintf("%05d", $counter);
$new_padded_value = $name . $num_padded;
echo $new_padded_value;
Im expecting it to echo Drew.00001
its not working. how can I achieve this.

You're missing a string dot between the vars. The dot that you used is just the string concatenation operator; it doesn't actually add a dot to the string result. Change:
$new_padded_value = $name . $num_padded;
To:
$new_padded_value = "$name.$num_padded";
Also change:
$name = Drew;
To:
$name = "Drew";

Related

How come id will not pass through link? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have a simple link that needs to pass a variable through $_GET and set it to a variable in the page that is being opened. It is failing every time however and I am not sure why.
<a class='section_header' href='category/index.php?`id='" . $catid . "'><b>" . $row[0] ."</b></a>
Code in category/index.php
$id = $_GET['id'];
echo $id;
<a class='section_header' href="category/index.php?id=<?php echo $catid?>"><b><?php echo $row[0];?></b></a>
Try
<a class='section_header' href='category/index.php?id='" . $catid . "'><b>" . $row[0] ."</b></a>
You had a random ` in there. Once it prints out you can use inspect element to make sure the url looks correct and id is populated.

how to add string to variable in php? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
i just need on small info i want just add '#' to one variable and and put add thing into one variable. i am adding small php code to here please suggest me.
<?php
$email34 = $row['email'];
$rem = '#gmail.com';
$trim_email = str_replace($rem ,'', $email34);
$tag_name ="#".$trim_emial.;
echo $tag_name;
?>
but i am getting only # as output;
but my out should be "#mahesh1" if any have idea about this code please help me. thank you advanced.
there is so much spelling mistakes in the variables... try below given code
<?php $email34 = $row['email'];
$rem = '#gmail.com';
$trim_email = str_replace($rem ,'', $email34);
$tag_name ="#".$trim_email;
echo $tag_name;
?>

My code is not working ($h.= ') [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Can anyone help me for this why doesn't my code work?
$h.= ' 'mysql_result($res,$z,"name")'';
It gives me an error because of the <a href
$h .= ''.mysql_result($res,$z,"name").'';
Should work now
. before mysql_result and after.
Also take a look here it will help you to understand String Operators and etc.
You need to concatenate.
$h.= ' ' . mysql_result($res,$z,"name") . '';
Anyway, I would suggest you to put mysql_result($res,$z,"name") into a variable, to increase readability and avoid executing the function every time you call it.
I mean:
$name = mysql_result($res,$z,"name");
$h.= ' ' . $name . '';
Try this
$h.= ''.mysql_result($res,$z,"name").'';
You are missing . the concatenation operator

PHP console does not echo [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Okay this really strange or I am missing something. When I run this very simmple PHP script on cmd I get the expected output which is 0. but when I uncomment the last two lines of code. . .nothing is displayed.
<?php
$test1 = 0;
echo $test1;
$test2 = 0;
#$test1_weight = 0:
#$test2_weight = 0;
?>
Is there some rule against declaring variables after an echo statement?
$test1_weight = 0:
--> change ":" to ";"
No there is no rule against declaring variables after an echo statement

echo out valuename in php [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
how can I print out a variable name in text in php?
I want to accomplish something as simple as having this:
echo "|" . "$myvariable" . "|";
print out this:
|$myvariable|
instead of this:
||
how can I accomplish this?
Use single quotes so that the variables don't get interpolated:
echo "|" . '$myvariable' . "|";
As others pointed out, use single quotes to show the variable name "as is".
echo "|" . '$myvariable' . "|";
Be sure to read this part of the manual.

Categories