Jump to content

mysql_numrows():


wernervantonder

Recommended Posts

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:

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

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

Link to comment
Share on other sites

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.abubusinessadmin.com/result.htm

Any body with an idea?????
Link to comment
Share on other sites

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']
Link to comment
Share on other sites

[quote author=xyn link=topic=108321.msg435670#msg435670 date=1158433625]
The problem i see is:
$num=mysql_numrows($result);
should be
$num=mysql_num_rows($result);
[/quote]

[quote=manual]Note: For downward compatibility, the following deprecated alias may be used: mysql_numrows() ...[/quote]
Link to comment
Share on other sites

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:

[code]
$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
}
[/code]

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.
Link to comment
Share on other sites

[quote author=wernervantonder link=topic=108321.msg435701#msg435701 date=1158438259]
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
[/quote]

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.