Can someone see why this select box doesnt display the numbers, but only the default text?

	include_once "connect_to_mysql.php";
	//Placing the page under the relevant subject, using a dropdown list
	$sqlCommand = "SELECT subjectid FROM pages ORDER BY subjectid ASC"; 
	$query = mysqli_query($myConnection, $sqlCommand) or die (mysql_error()); 
	while ($row = mysqli_fetch_array($query)) {
			$subjectid = $row['subjectid'];
	<p><b>Place Your Page for subject:&nbsp;<span class="required">*</span></b></p>
    <i>This is the position of your link!</i><br />
	<select class="boxstyles" name="subjectposition">
	echo "<option>Choose A Subject For Your Page&nbsp;</option>";?>
	$result = mysqli_query($myConnection, $query);
	$subject_count = mysqli_num_rows($result);
		// Subject_count +1 b/c adding a subject
		for($count=1; $count < $subject_count+1; $count++) {
		echo "<option value=\"{$count}\">{$count}&nbsp;</option>";	

I am using this to place a page under whatever subject the user decides, and using the subjectid for this.

So the select box should display display the relevant numbers, but I only get the default text: "Choose A Subject For Your Page"?

But nothing gets counted in the way I have made this?


Recommended Answers

All 2 Replies

on line 16, $query is NOT an sql command (You already have a result set in $query from the executed sql command on line 5), so it is essentially erroring out before it can emit those other options (look at the browser source code).

On what you posted, I don't see the point of lines 6-8 since:
a. You keep overwriting the value of $subjectid on every iteration of your loop
b. You are not using it anywhere else
c. You intended to execute the same query again to generate the options. Why not just use what's in $query

Thanks a lot! Solved :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.