Computing.Net > Forums > Web Development > PHP Code

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PHP Code

Reply to Message Icon

Name: Guandaru
Date: May 19, 2009 at 01:41:35 Pacific
OS: Windows XP
Subcategory: PHP
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: shutat
Date: May 19, 2009 at 12:47:31 Pacific
Reply:

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


0

Response Number 2
Name: Guandaru
Date: May 19, 2009 at 19:17:45 Pacific
Reply:

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


0

Response Number 3
Name: RealTrack
Date: May 20, 2009 at 03:38:22 Pacific
Reply:

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

help would be much appreciated

thanks
nalin




0

Response Number 4
Name: shutat
Date: May 20, 2009 at 14:37:30 Pacific
Reply:

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 table

I'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


0

Response Number 5
Name: shutat
Date: May 20, 2009 at 14:40:53 Pacific
Reply:

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

help 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


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: PHP Code

simple php codes www.computing.net/answers/webdevel/simple-php-codes/449.html

AIM and PHP code for web design www.computing.net/answers/webdevel/aim-and-php-code-for-web-design/1001.html

HELP needed with php codes www.computing.net/answers/webdevel/help-needed-with-php-codes/3006.html