• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

php dynamic list help

MBrown

Diamond Member
I'm trying to make a dynamic list that pulls a pk from a database, but I am running into some stupid parse errors and I cannot see what the issue is. Can someone with some fresh eyes check this out? Thanks!

This is the error: Parse error: syntax error, unexpected '"'>"' (T_CONSTANT_ENCAPSED_STRING)

this is the function

Code:
function serialDropdown($listQuery, $con)
	{
	 $list = mysql_query($listQuery, $con);
	 $menu = "<select name = 'serialNumberList'>";
	 while ($result = mysql_fetch_array($list))
	 {
		// The line below is the one that keeps giving me errors!
		$menu .= "<option value=' ".$result['serialNumber'] "'>" .$result['serialNumber'] ." </option>";
	 }
		$menu .= "</select>";
		return $menu;
         }


UPDATE!!!!!!!

Ok. I'm trying a different approach now, but for some reason it is not displaying my first result. For example in my table I have 7 rows but its only displaying 2 through 7 in my list. I cannot see where my issue is. Anyone else see it?

Code:
$listRows = mysqli_num_rows($listQuery);
	echo "<br /> <br /> <br />";
	echo "<select name = 'serialNumberlist'>";
	for ($y = 0; $y < $listRows; ++$y)
	{
		$listRows = mysqli_fetch_row($listQuery);
		for ($x = 0; $x < 1; $x++)
		{
			echo "<option value = '$listRows[$x]'> $listRows[$x] </option>";
		}
	}
        echo "</select>";

Thanks in advance!
 
Last edited:
Not a php guy, but going out on a limb to suggest you take a really careful look at the order and number of single vs. double quotes.
 
Not a php guy, but going out on a limb to suggest you take a really careful look at the order and number of single vs. double quotes.

Double check and double checked. I was using notepad++ for this but I installed phpstorm 30 day trial and its saying that it needs a semicolin to end the line of code but that is just not correct.
 
Missing a . (period) before the " for the string concatenation

.$result['serialNumber'] "'>"

That's why it's saying you need a ; there.
 
Ok. I'm trying a different approach now, but for some reason it is not displaying my first result. For example in my table I have 7 rows but its only displaying 2 through 7 in my list. I cannot see where my issue is. Anyone else see it?

Code:
$listRows = mysqli_num_rows($listQuery);
	echo "<br /> <br /> <br />";
	echo "<select name = 'serialNumberlist'>";
	for ($y = 0; $y < $listRows; ++$y)
	{
		$listRows = mysqli_fetch_row($listQuery);
		for ($x = 0; $x < 1; $x++)
		{
			echo "<option value = '$listRows[$x]'> $listRows[$x] </option>";
		}
	}
        echo "</select>";

Thanks in advance!
 
try this:
$listRows = mysqli_num_rows($listQuery);
echo "<br /> <br /> <br />";
echo "<select name = 'serialNumberlist'>";
for ($y = 0; $y < $listRows; ++$y)
{
$listRows = mysqli_fetch_row($listQuery);
for ($x = 0; $x < 1; $x++)
{
echo "<option value = ".$listRows[$x].">". $listRows[$x]."</option>"; // changed quote type and add concatenation dots
}
}
echo "</select>";
 
Why are you using $listRows for both the count and the fields for each fetched row?

try using $row inside the loop, or $listcount for the count of rows.
 
When you call mysqli_fetch_row it increments the internal pointer so that`s why when you echo the dropdown it skips one.
 
Why are you using $listRows for both the count and the fields for each fetched row?

try using $row inside the loop, or $listcount for the count of rows.

tried this but it didn't work. I used this same loop set up to display a table of data and it works perfectly. I figured I could implement this into my drop down list. Also it seems that it is displaying the correct number of options, but the first option always says its 2 and the last option is always blank.
 
Back
Top