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 Link to comment https://forums.phpfreaks.com/topic/37588-blank-output/ 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. Link to comment https://forums.phpfreaks.com/topic/37588-blank-output/#findComment-179936 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? Link to comment https://forums.phpfreaks.com/topic/37588-blank-output/#findComment-179993 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(); ?> Link to comment https://forums.phpfreaks.com/topic/37588-blank-output/#findComment-179997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.