954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Missing database info in select box

Everyone,

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

<?php 
	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>
	<select class="boxstyles" name="subjectposition">
	<?php
	echo "<option>Choose A Subject For Your Page&nbsp;</option>";?>
    <?php
	$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>";	
		} 
	?>
	</select>


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?

Klemme

klemme
Posting Whiz in Training
265 posts since Mar 2011
Reputation Points: 18
Solved Threads: 7
 

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. Youintended to execute the same query again to generate the options. Why not just use what's in $query

hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244
 

Thanks a lot! Solved :-)

klemme
Posting Whiz in Training
265 posts since Mar 2011
Reputation Points: 18
Solved Threads: 7
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: