Hey DP PHP experts! Any idea on why doesn't this code work? Obviously it's because of the <?=$id?> bit. But in the rest of the document the <?=$id?> function works well. It's the session of the users ID. How do I make it work within the <? ?> php parameters? Thanks in advance!
You already have PHP on. Can't turn it twice. Try this: ? $data = mysql_query("SELECT * FROM gg_event WHERE id='{$id}' ORDER BY id DESC LIMIT 20"); while($row = mysql_fetch_array($data)) { echo " ".$row[client_name]." "; } ?> PHP:
$data = mysql_query("SELECT * FROM gg_event WHERE id=" . $id . " ORDER BY id DESC LIMIT 20"); This should do the trick
Did you miss the < before ? on purpose ? Anyways, it doesn't seem to work. I understand that you changed to '{$id}' That doesn't cause the page to crash which is progress But for some reason it doesn't call out the right results. It should call out results that are associated with the user whom that page belongs to. Hhmmm
Ok, that does the same as with the other code (first answer in this thread) Hmm... for some reason the $id doesn't associate the query with the user whom the page belongs to. It's supposed to give out all of the events that happened to the user. <a href="#/gallery/user/<?=$id?> - that is how the code for his gallery URL (the users) is generated within that same php document. Odd, huh?
Ok. Let's begin with a bit of theory. PHP is different from html. While regular html can be executed in a .php file, php code can not be executed in a normal .html file. It is possible, but not recommended. Any code that you type into a .php page that is not within <?php and ?> will be executed as html, and not as php. Once those two tags are open, everything will be executed as php, even if your code is html and not inside an echo or print function. So you don't need <?=$id?> if it's going between <?php and ?>. You'll need it if it's not going between those two. As for the above, I did not mean to miss the <, and it should have been there.
Assuming the $id value is numeric use Or possibly but not " inside a query string that is alread enclosed in " " and right before that query line insert the following line to make sure the variable is valid to start with: