Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am writing a html class attribute which need space to allow multiple values. However, among these values, there are variables and constants. Code shows below:
<article id="portfolio-item-1" data-loader="include/ajax/portfolio-ajax-image.php" class="value1 value2">
Here I want value1 in the class to be a variable like $itemTitle, but still to maintain the "value2" with a space between them.
I have tried many method like add   and using
echo $itemName." "."value2";
but seems didn't work.
Any ideas?
Thanks!
Solved:
Solution1:
<article id="portfolio-item-1" data-loader="include/ajax/portfolio-ajax-image.php" class="<?php echo "$item->category_id"." "."value0"; ?>" >
Solution2:
<article id="portfolio-item-1" data-loader="include/ajax/portfolio-ajax-image.php" class="<?php echo "$item->category_id Value0"; ?>" >
Thanks!
<?php
echo "$itemName value2";
?>
If you use double quotes, you can drop the variable right in there, no concatenation needed!
<article id="portfolio-item-1" data-loader="include/ajax/portfolio-ajax-image.php" class="<?php echo "$itemName value2"; ?>">
It is not an error to have a space without a class on each side.
echo '<article... class="'.$itemName.' value2"...
$id = 'portfolio-item-1';
$url = 'include/ajax/portfolio-ajax-image.php';
echo '<article id="'.$id.'" data-loader="'.$url.'" class="'.$itemName.' value2">';
will work, for instance.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
New to php and i have tried what I thought would work but it didnt work.
I have an image in my upload folder name 1002386235.png the number 1002386235 is the user id and I would like to display a profile picture of the user with the help of php. With this I can display the image. What I am trying to achieve is replace the 1002386235.png with something like $uid.png, $uid being a variable with the user id in it. I thought the following would work but it didnt
<?php
$uid = "1002386235";
?>
<img src="upload/".$uid.".png">
You need to wrap the variable $uid within php tags and since your html is not inside php tags, the concatenation dot operators are not required. Also, you need to echo the variable inside your html.
Change this line:
<img src="upload/".$uid.".png">
To this:
<img src="upload/<?php echo $uid; ?>.png">
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
i want to echo a div in PHP, and set the ID equal to the value of $divName, but i cannot get it to work
Here is my code:
$divName = "divText"
echo '<div id=$divName></div>'
Just do it like this:
$divName = "divText";
echo '<div id="'.$divName.'"></div>';
You should read the PHP Documentation. This is really basic stuff.
http://php.net/docs.php
Why you don't add semicolons (;) at the end of each command line?
Change single quotes (') to double quotes (") and that it:
$divName = "divText";
echo "<div id=$divName></div>";
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I got something like this: print '<img src="'.$rlink.'">';
it shows me right link, but image doesn't appear. When I go to browser console, I get this error: http://somesite.com/somesite.com/thisimage.jpg
I tried <img src="<? php echo $rlink; ?>"/>
It is not working. I was looking around forums but didn't found a solution. Thank you for any help!
<img src="<? php echo $rlink; ?>"/>
needs to be:
<img src="<?php echo $rlink ?>">
it might not solve the problem because i dont kno what the value of the variable is. It might be wrong.
I'm guessing your variable $rlink contains somesite.com/thisimage.jpg. Since it doesn't have a protocol at the beginning, the browser thinks it's a relative path, thus trying to go to somesite.com folder, which doesn't exist. You can either put http:// at the beginning of the src, or remove domain so it's treated like the relative path it is as of now
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
So-.. I was looking up how to fix this function; but I can't seem to find out. Can anyone give a hand?
I get an error on this line ( I'll include the php function ).
PHP function:
while($sql_row = mysqli_fetch_row($result))
Actual faulty line:
<tr>
<td><a <?php echo 'href="character_staff.php?action=manage&name=' . $sql_row[0] . '"'; ?>><?php echo $sql_row[0]; ?></a></td>
<td><a <?php echo 'href="character_staff.php?action=manage&name=' . $sql_row[0] . '"'; ?>><?php echo $sql_row[2]; ?></a></td>
</tr>
I can't seem to find out how to fix it. It has to change the URL into a link that contains text ( IE: character_staff.php?action=manage&name=account_name )
The problem is here:
<?php echo $sql_row[2]; ?>
Your code is attempting to echo the third element of the $sql_row array, but the array does not contain three elements. There are two ways to fix the problem: change the code to reference only elements that exist in the array, or change the array to contain more elements.
Note: in case you are wondering why $sql_row[2] looks for the third element, it is because arrays are zero-indexed.
$sql_row[0]
returns the first element.
$sql_row[1]
returns the second element, and so on.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
My code is random but its does not print out the picture just the text. When I add the IMAGE tag. Its go all wrong. Where do I go wrong?
$plaatje[] = 'afbeelding1.jpg';
$plaatje[] = 'afbeelding2.jpg';
$plaatje[] = 'afbeelding3.jpg';
$plaatje[] = 'afbeelding4.jpg';
$nummer2 = mt_rand(1,4);
echo "$plaatje[$nummer2]";
Use array_rand() - Picks one or more random entries out of an array
echo $plaatje[array_rand($plaatje)];
With an image tag, something like:
<img src="<?php echo $plaatje[array_rand($plaatje)]; ?>" />
or
echo "<img src='".$plaatje[array_rand($plaatje)]."' />";
Here is the documentation
Although you should add the image tag to show where it goes wrong, your code already has a problem as array indices are 0-based.
So you would need:
$nummer2 = mt_rand(0,3);