/    Sign up×
Community /Pin to ProfileBookmark

img id in echo?

tried this but it doesnt work.

[code=php]
echo “<img id='”.$id.”‘>

[/code]

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@jag1authorJul 01.2015 — [CODE]

echo "<img id='".$id."'>";

[/CODE]
Copy linkTweet thisAlerts:
@NogDogJul 01.2015 — Define "doesn't work".

Do you know for sure that $id has a value at that point?

In any case, it's not necessary to use concatenation with a simple scalar variable like that:
[code=php]
echo "<img id='$id'>";
[/code]
Copy linkTweet thisAlerts:
@jag1authorJul 01.2015 — yea I have it set to
[code=php]

$id = "id_test";

[/code]


I mean that if i switch the width in the css the image is still as big as before. Or if i make rounded corners in the css the images corners are still straight.
Copy linkTweet thisAlerts:
@ginerjmJul 01.2015 — How is this little snippet of php code supposed to interact/conflict with some piece of css?

You're not presenting yourself very well.
Copy linkTweet thisAlerts:
@jag1authorJul 01.2015 — How is this little snippet of php code supposed to interact/conflict with some piece of css?

You're not presenting yourself very well.[/QUOTE]


[CODE]
<?php

include_once 'dbconnect.php';
session_start();
$id = "id_test";

$result = mysqli_query($con,"SELECT * FROM users");

?>
<table id="table" style="width:100%">
<tr>
<td> <a href="#" class="class_5" style="cursor: pointer;">
<?php

if($row['image'] == ""){
echo "<img id='$id' src='pictures/test1.jpg'>";
}
else {
echo "<img id='$id' src='pictures/".$row['image']."' ";
}?>

</td>

</tr>
</table>


[/CODE]
Copy linkTweet thisAlerts:
@r8rJul 01.2015 — I mean that if i switch the width in the css the image is still as big as before. Or if i make rounded corners in the css the images corners are still straight.[/QUOTE]

What does the HTML-output say? Is the id printed in there as you would expect? If yes, then you have a CSS problem; if no, then it might be PHP related. Is PHP enabled on your server at all?
Copy linkTweet thisAlerts:
@ginerjmJul 01.2015 — You still haven't said what doesn't work as expected. Forums are very big on questions and answers and you aren't answering the questions you have been given.

Nor does this code work very well.

You are obviously new at this and are copying code from various places and pasting them together, thinking they will work, and not even reading and comprehending what you have wrought.

1 - You run a query but you never get any result from it to work with.

2 - You are referencing an undefined array to make decisions on how to proceed in your code. Not gonna happen.

3 - You have a mistake in your html output from the else clause which is probably the only code that gets output.

Turn on php error checking and see what you get. Then try and read up on how to properly code up a query and run it and get results back from it. Could be very enlightening.
Copy linkTweet thisAlerts:
@jag1authorJul 01.2015 — What does the HTML-output say? Is the id printed in there as you would expect? If yes, then you have a CSS problem; if no, then it might be PHP related. Is PHP enabled on your server at all?[/QUOTE]

Thank you i solved it
Copy linkTweet thisAlerts:
@jag1authorJul 01.2015 — You still haven't said what doesn't work as expected. Forums are very big on questions and answers and you aren't answering the questions you have been given.

Nor does this code work very well.

You are obviously new at this and are copying code from various places and pasting them together, thinking they will work, and not even reading and comprehending what you have wrought.

1 - You run a query but you never get any result from it to work with.

2 - You are referencing an undefined array to make decisions on how to proceed in your code. Not gonna happen.

3 - You have a mistake in your html output from the else clause which is probably the only code that gets output.

Turn on php error checking and see what you get. Then try and read up on how to properly code up a query and run it and get results back from it. Could be very enlightening.[/QUOTE]


Thanks i got it to work
Copy linkTweet thisAlerts:
@ginerjmJul 01.2015 — Hth
×

Success!

Help @jag1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...