Jump to content


Photo

mysql_numrows():


  • Please log in to reply
7 replies to this topic

#1 wernervantonder

wernervantonder
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 16 September 2006 - 06:52 PM

Good day to everyone! I am desperate for help:
i just want to say thank you very much for helping me!

I have craeted a database wich contains info on businesses contact details.  i have a page called index.html and its form contains two list boxes and a submit button. when i press submit it follows the "action" of opening results.php. basicly i want it to search the database and filter from 2 index fields the data that was selected in the list boxes on the index.html page. how ever i get this error:

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in c:\program files\easyphp1-8\www\results.php on line 19

basicly i use a loop to display my data in tables. Here is my code for that php page:

<?
include("topresults.html");
?>
<?
include("connect.php");

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

//collect data sent from form
$area = $_POST['area'];
$category = $_POST['services'];

$querysuburb = " SELECT*FROM $table
WHERE area=$area
AND category=$category";
//this is where my error lies
$result=mysql_query($querysuburb); 
$num=mysql_numrows($result);


mysql_close();

echo "<b><center>Your Search Results matching Area: $area and Category: $category</center></b><br><br>";

$i=0;
while ($i < $num) {

$ID=mysql_result($result,$i,"ID");
$company=mysql_result($result,$i,"company");
$name=mysql_result($result,$i,"name");
$tel=mysql_result($result,$i,"tel");
$cel=mysql_result($result,$i,"cel");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$address=mysql_result($result,$i,"address");
$area=mysql_result($result,$i,"area");
$suburb=mysql_result($result,$i,"suburb");
$category=mysql_result($result,$i,"category");
$logo=mysql_result($result,$i,"logo");
$weblink=mysql_result($result,$i,"weblink");

#start building an HTML table that uses $table
$list = "<table width=\"350\" border=\"1\" cellpadding=\"2\" cellspacing=\"7\" bordercolor=\"#000000\" class=\"right_articles\">";
$list .= "<tr><th>Company Name </th> ";
$list .= "<td>".$company."</td>";
$list .= "<tr><th>Name</th>";
$list .= "<td>".$name."</td>";
$list .= "<tr><th>Telephone Number</th>";
$list .= "<td>".$tel."</td>";
$list .= "<tr><th>Cellular</th>";
$list .= "<td>".$cel."</td>";
$list .= "<tr><th>FAX</th>";
$list .= "<td>".$fax."</td>";
$list .= "<tr><th>E-Mail</th>";
$list .= "<td>".$email."</td>";
$list .= "<tr><th>Address</th>";
$list .= "<td>".$address."</td>";
$list .= "<tr><th>Metropolitan Area</th>";
$list .= "<td>".$area."</td>";
$list .= "<tr><th>Suburb</th>";
$list .= "<td>".$suburb."</td>";
$list .= "<tr><th>Category</th>";
$list .= "<td>".$category."</td>";
$list .= "<tr><th>Website Address</th>";
$list .= "<td>".$weblink."</td>";
$list .="</table><br>";

echo( $list);
$i++;
}

?>

<?
include("bottom.html")
?>

Thank you so much in advance for your help it is greatley appreciated!

Regards
Werner



#2 maitechnology

maitechnology
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 16 September 2006 - 06:59 PM

My problem is :

I have result_database, containg 10 tables for student result score, I already generated pin numbers to be used to access thier result online, the will use their registration number, category, and pin number to access it, but I wanted it in such a way that once, a pin is used to access a particular result, that pin should only be recognised for that result, cannot be used for another  student. So I want suitable pin number validation, already student cannot use wrong pin nos.


This the link to the page I am working on for clear understanding of the probelm.....
umar_albashir: http://www.abubusine....com/result.htm

Any body with an idea?????


#3 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 16 September 2006 - 07:07 PM

The problem i see is:
$num=mysql_numrows($result);
should be
$num=mysql_num_rows($result);

#4 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 16 September 2006 - 08:00 PM

xyn is right, the function call is mysql_num_rows($result);

Also FYI, there is no need to create all new variables for each POST or GET variable. Makes your life harder and takes up extra resources. For example this is bad:

//collect data sent from form
$area = $_POST['area'];
$category = $_POST['services'];

Just simply use the variables as they are:

$_POST['area']

#5 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 16 September 2006 - 08:04 PM

The problem i see is:
$num=mysql_numrows($result);
should be
$num=mysql_num_rows($result);


Note: For downward compatibility, the following deprecated alias may be used: mysql_numrows() ...



#6 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 16 September 2006 - 08:05 PM

Also, what the hell is up with this?

$ID=mysql_result($result,$i,"ID");
$company=mysql_result($result,$i,"company");
$name=mysql_result($result,$i,"name");
$tel=mysql_result($result,$i,"tel");
$cel=mysql_result($result,$i,"cel");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$address=mysql_result($result,$i,"address");
$area=mysql_result($result,$i,"area");
$suburb=mysql_result($result,$i,"suburb");
$category=mysql_result($result,$i,"category");
$logo=mysql_result($result,$i,"logo");
$weblink=mysql_result($result,$i,"weblink");

Way too much work. Simply do a while loop. So you have:

$result=mysql_query($querysuburb) or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
 #start building an HTML table that uses $table
$list = "<table width=\"350\" border=\"1\" cellpadding=\"2\" cellspacing=\"7\" bordercolor=\"#000000\" class=\"right_articles\">";
$list .= "<tr><th>Company Name </th> ";
$list .= "<td>". $row['company'] ."</td>";
//ETC
}

On thing to note, the variables now you stick inside the $row array must match the name of the fields in the database, not what you called the variable in the form. BUT ALWAYS a good idea to make sure your variable names in the form MATCH exactly what you call the variable in mysql, that way no confusion ever.

#7 wernervantonder

wernervantonder
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 16 September 2006 - 08:24 PM

Thank you everyone i shall try what you reccomended! i am still a beginner at php so i might just ask some more.

if that is ok?

Werner

#8 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 08:53 PM

Thank you everyone i shall try what you reccomended! i am still a beginner at php so i might just ask some more.

if that is ok?

Werner


Absolutely fine!  All you need to be sure of is that you have already tried to solve your problem (after all, it's yours not ours), and then post something descriptive along with what you think is wrong or not working and some of your code.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users