Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am using the code mysql_num_rows($result); to get results from a table and my web server is giving a error yet my local host is working ok.
Which is an alternative code for this.

What's your query? You might try using:
$res = mysql_query(...); if(is_resource($res)) { ... }It won't give you an integer value, but you can use it to determine whether or not the query was successful. On your host, have you tried using mysql_error() to see the reason why num_rows is failing?
You might also want to run phpinfo() to check whether or not mysql_num_rows is a function that your host has disabled...HTH
______________________
My work in progress. I hate JS. :P

This is my code. i want to get results from a database and post them to a table. My server still reports a error on the line
$num=mysql_num_rows($result); even when i use $num=mysql_numrows($result);is there an alternative
thanks
<?php
mysql_connect(localhost,"ecolink_charles","*131#");
@mysql_select_db("ecolink_Contacts") or die( "Unable to select database");
$query="SELECT * FROM service_request";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();
echo "<center>Database Output</center>";
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"name");
$phone=mysql_result($result,$i,"phone");
$email=mysql_result($result,$i,"email");
$org=mysql_result($result,$i,"organisation");
$location=mysql_result($result,$i,"location");
$service=mysql_result($result,$i,"service");
$description=mysql_result($result,$i,"description");
?>
<table border="0" cellspacing="2" cellpadding="2" width="100%">
<tr>
<td bgcolor="#0000CC" colspan="2"><?php echo $i+1 ?></td>
</tr>
<tr>
<td>Name</p>
</td>
<td>
<?php
echo "$name" ?></p></td></tr>
<tr>
<td>Phone</p>
</td>
<td>
<?php
echo "$phone" ?></p></td></tr>
<tr>
<td>Email</p>
</td> <td>
<?php
echo "$email" ?></td></tr>
<tr>
<td>Organisation</p>
</td> <td>
<?php
echo "$org"?></p></td></tr>
<tr>
<td>Location</p>
</td> <td>
<?php
echo "$location" ?></p></td></tr>
<tr>
<td>Service</p>
</td> <td>
<?php
echo "$service"?></p></td></tr>
<tr>
<td>Description</p>
</td> <td>
<?php
echo "$description"?></p></td>
</tr></table>
<?php

Hi would anyone be able to help me to find out readymade
php codes which are available for free on internethelp would be much appreciated

If your database has an auto_incrementing primary key, then you might try two queries.
$res = mysql_query("select primary_key_name from table order by" . "primary_key_name desc limit 1;") or die(mysql_error()); $row = mysql_fetch_row($res); $num = $row[0]; // hopefully will be the number of valid records in the tableI'm curious why you're not using mysql_fetch_assoc instead of looping through.
$res = mysql_query("select * from service_request;"); if(is_resource($res)) { while($row = mysql_fetch_assoc($res)) { foreach($row as $key => $val) { echo $key . " = " . $val . "<br />"; } } }You could also try using a scrolling div to help contain the results within a manageable area. For example
<div style="height: 250px; overflow: auto"> <?php retrieve and output query details ?> </div>HTH
______________________
My work in progress. I hate JS. :P

Hi would anyone be able to help me to find out readymade
php codes which are available for free on internethelp would be much appreciated
You might try milling over this page and /or here or here. Hopefully, one or more will have something that you can make use of.
Good luck.
______________________
My work in progress. I hate JS. :P

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |