Jump to content

help with escape characters I believe


kramerkeller

Recommended Posts

My HTML intention is this

<option value="username"> firstname lastname </option>

 

Pretty simple - except I am inputting username, firstname, lastname from a database

 

HELP - here is the code belowe

 

 

$result = get_users();

$num_results = $result->num_rows;

echo"<select name='salesperson'>";

for ($count = 0; $count<$num_results; $count++)

 {

   $row = $result->fetch_assoc();

echo "<option value='".$row['username']."'>".$row['firstname']." ".$row['lastname']."</option>";

 }

?>

Link to comment
https://forums.phpfreaks.com/topic/36533-help-with-escape-characters-i-believe/
Share on other sites

I don't see any problem with that code. What problems are you experiencing?

 

It could be a little more efficient. Are you just wanting to have double quotes instead of single quotes int he output? If so, try this:

<?php

$result = get_users();

echo"<select name='salesperson'>";
while ($row = $result->fetch_assoc()) {
  { 
   echo "<option value=\"{$row['username']}\">{$row['firstname']} {$row['lastname']}</option>";
  }
?>

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.