NameSilo

PHP Help!

Spaceship Spaceship
Watch

Ik

Quality //VIP Member
Impact
8
This is driving me crazy.

My code below displays 3 records, sometimes 1 record, while there are 5 matching records! I did output the $num and it was 5, but not all the 5 records are displayed. Help please. Code below:
Code:
<ul>

<?php
	include("siteconfig.php");
	
	// connect to server and select databse
	$conn = mysql_connect("$host", "$username", "$password") or die("cannot connect!");
	mysql_select_db("$db_name")or die("cannot select database!");
	
	// execute sql
	$sql = "select * from pages where parentid = 0 and online = 1";
	$result = mysql_query($sql) or die('error, insert query failed');
	
	// close connection
	mysql_close($conn);
	
	// get number of records
	$num = mysql_numrows($result);
	
	$i=0;
	if($num > 0)
	{
		while ($i < $num)
		{
			echo "<li><a href='page.php?pid=".mysql_result($result,$i,"pid").">".mysql_result($result,$i,"title")."</a></li>";
			$i++;
		}
	}
?>

</ul>


---------- Post added at 12:16 AM ---------- Previous post was at 12:01 AM ----------

OMG, I got it; I was missing a single quote :) Thanks everyone
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Glad you fixed it, a lot of times its the little things ...
 
0
•••
btw, you should be using mysql_num_rows instead of mysql_numrows

Note: For backward compatibility, the following deprecated alias may be used: mysql_numrows()
PHP: mysql_num_rows - Manual

It's deprecated, meaning it could be removed at any time from the php core
 
0
•••
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back