phpcod3r Posted February 8, 2007 Share Posted February 8, 2007 <? $username="cnt"; $password="hi"; $database="contacts"; mysql_connect(localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM contacts"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); $phone=mysql_result($result,$i,"phone"); $mobile=mysql_result($result,$i,"mobile"); $fax=mysql_result($result,$i,"fax"); $email=mysql_result($result,$i,"email"); $web=mysql_result($result,$i,"web"); echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>"; $i++; } ?> The above code is placed in gb.php and when i run it on my XAMPP lite it just shows Database Output text and the rest of the page is blank, where can be the problem. Thanks Quote Link to comment Share on other sites More sharing options...
fenway Posted February 8, 2007 Share Posted February 8, 2007 That's the least efficient way to work with a result set -- you should be using a while loop and interating on mysql_fetch_assoc(). Not sure why the numrows() call isn't working though... but it's not necessary. Quote Link to comment Share on other sites More sharing options...
phpcod3r Posted February 8, 2007 Author Share Posted February 8, 2007 I was just test codes, any hints on how to fix them? Quote Link to comment Share on other sites More sharing options...
fenway Posted February 8, 2007 Share Posted February 8, 2007 <? $username="cnt"; $password="hi"; $database="contacts"; mysql_connect(localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM contacts"; $result=mysql_query($query); $num=mysql_numrows($result); echo "<b><center>Database Output</center></b><br><br>"; while ($row = mysql_fetch_assoc( $result ) ) { $first=$row['first']; $last=$row['last']; $phone=$row['phone']; $mobile=$row['mobile']; $fax=$row['fax']; $email=$row['email']; $web=$row['web']; echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>"; } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.