Jump to content

[SOLVED] Mysql_num_rows problem.


GB_001

Recommended Posts

I keep getting an odd error with this code.

 

<?php
@mysql_connect("mysql.x10hosting.com", "gb_GB", "********") or die(mysql_error());
@mysql_select_db("gb_USERInfo") or die(mysql_error());

session_start();
//specify how many results to display per page
$limit = 20;

// Get the search variable from URL
$var = @$_GET['q'] ;
//trim whitespace from the stored variable
$trimmed = trim($var);
//separate key-phrases into keywords
$trimmed_array = explode(" ",$trimmed);

// check for an empty string and display a message.
if ($trimmed == "") {
$resultmsg = "<p>Search Error</p><p>Please enter a search...</p>" ;
}

// check for a search parameter
if (!isset($var)){
$resultmsg = "<p>Search Error</p><p>We don't seem to have a search parameter! </p>" ;
}
// Build SQL Query for each keyword entered
foreach ($trimmed_array as $trimm){

// EDIT HERE and specify your table and field names for the SQL query
$query = "SELECT * FROM Ysers WHERE School/Office LIKE \"%$trimm%\" OR Location LIKE \"%$trimm%\" OR email LIKE \"%$trimm%\" ORDER BY field1 DESC" ;
// Execute the query to get number of rows that contain search kewords
$results= mysql_query($query);
$row_num = mysql_numrows ($results);

// next determine if 's' has been passed to script, if not use 0.
// 's' is a variable that gets set as we navigate the search result pages.
if (empty($s)) {
$s=0;
}

// now let's get results.
$query .= " LIMIT $s,$limit" ;
$results = mysql_query ($query) or die ( "Couldn't execute query" );
$row= mysql_fetch_array ($results);
}

if($row_num_links_main == 0 && $row_set_num == 0){
$resultmsg = "<p>Search results for:" . $trimmed ."</p><p>Sorry, your search returned zero results</p>" ;
}

else{

// Make a MySQL Connection

while($row = mysql_fetch_array($result)){
echo $row['firstname'];
echo $row['School/Office'];
echo $row['Location'];
echo "<br />";
}
}

?>

 

Error: Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/gb/public_html/Friendsearch.php on line 32

Couldn't execute query

 

Thankyou for your help, this is a great community.

Link to comment
Share on other sites

What error does this spit out ?

 

<?php
@mysql_connect("mysql.x10hosting.com", "gb_GB", "redman12345") or die(mysql_error());
@mysql_select_db("gb_USERInfo") or die(mysql_error());

session_start();
//specify how many results to display per page
$limit = 20;

// Get the search variable from URL
$var = @$_GET['q'] ;
//trim whitespace from the stored variable
$trimmed = trim($var);
//separate key-phrases into keywords
$trimmed_array = explode(" ",$trimmed);

// check for an empty string and display a message.
if ($trimmed == "") {
$resultmsg = "<p>Search Error</p><p>Please enter a search...</p>" ;
}

// check for a search parameter
if (!isset($var)){
$resultmsg = "<p>Search Error</p><p>We don't seem to have a search parameter! </p>" ;
}
// Build SQL Query for each keyword entered
foreach ($trimmed_array as $trimm){

// EDIT HERE and specify your table and field names for the SQL query
$query = "SELECT * FROM Ysers WHERE School/Office LIKE \"%$trimm%\" OR Location LIKE \"%$trimm%\" OR email LIKE \"%$trimm%\" ORDER BY field1 DESC" ;
// Execute the query to get number of rows that contain search kewords
$results= mysql_query($query)or die (mysql_error());
$row_num = mysql_numrows ($results);

// next determine if 's' has been passed to script, if not use 0.
// 's' is a variable that gets set as we navigate the search result pages.
if (empty($s)) {
$s=0;
}

// now let's get results.
$query .= " LIMIT $s,$limit" ;
$results = mysql_query ($query) or die (mysql_error());
$row= mysql_fetch_array ($results);
}

if($row_num_links_main == 0 && $row_set_num == 0){
$resultmsg = "<p>Search results for:" . $trimmed ."</p><p>Sorry, your search returned zero results</p>" ;
}

else{

// Make a MySQL Connection

while($row = mysql_fetch_array($result)){
echo $row['firstname'];
echo $row['School/Office'];
echo $row['Location'];
echo "<br />";
}
}

?>

Link to comment
Share on other sites

Okay, so I redid the code and I still get the same error.

 

<?php
@mysql_connect("mysql.x10hosting.com", "gb_GB", "***********") or die(mysql_error());
@mysql_select_db("gb_USERInfo") or die(mysql_error());

session_start();
//specify how many results to display per page

// Get the search variable from URL
$var = @$_GET['Email'] ;

$trim = trim($var);

$array = explode(" ",$trim);

foreach ($array as $array){

if ($trim == "") {
$resultmsg = "<p>Search Error</p><p>Please enter an email...</p>" ;
}

$query = "SELECT * FROM Ysers WHERE email LIKE \"%$array%\" ORDER BY email DESC" ;
$results=mysql_query ($query) or die (mysql_error());
$row_num =mysql_num_rows ($numresults) or die (mysql_error());;

$numresults = mysql_query ($query) or die ( "Couldn't execute query" );
$row= mysql_fetch_array ($numresults);

do{
//EDIT HERE and specify your field name that is primary key
$adid_array[] = $row[ 'id' ];
}while( $row= mysql_fetch_array($numresults));
} //end foreach

$tmparr = array_unique($adid_array);
$i=0;
foreach ($tmparr as $v) {
$newarr[$i] = $v;
$i++;
}

while($row = mysql_fetch_array( $numresult ) or die (mysql_error())) {
// Print out the contents of each row
echo $row['name']." - ".$row['email']. "<br />";
} 

 

Error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/gb/public_html/Friendsearch.php on line 24

Link to comment
Share on other sites

You're passing the wrong variable to the mysql_num_rows() function. It should be be $results, not $numresults. Same goes for call to mysql_fetch_array():

 

 

$query = "SELECT * FROM Ysers WHERE email LIKE \"%$array%\" ORDER BY email DESC" ;
$results=mysql_query ($query) or die (mysql_error());
$row_num =mysql_num_rows ($results);
$row= mysql_fetch_array ($results);

 

Dane: FYI, mysql_numrows() is an alias for mysql_num_rows(), though it is depreciated.

Link to comment
Share on other sites

[code][code]<?php
@mysql_connect("mysql.x10hosting.com", "gb_GB", "********") or die(mysql_error());
@mysql_select_db("gb_USERInfo") or die(mysql_error());

session_start();

$var = @$_GET['Email'] ;

$trim = trim($var);

$array = explode(" ",$trim);

foreach ($array as $array){

if ($trim == "") {
$resultmsg = "<p>Search Error</p><p>Please enter an email...</p>" ;
}

$query = "SELECT * FROM Ysers WHERE email LIKE \"%$array%\" ORDER BY email DESC" ;
$results=mysql_query ($query) or die (mysql_error());
$row_num =mysql_num_rows ($results);
$row= mysql_fetch_array ($results);
$numresults = mysql_query ($query) or die ( "Couldn't execute query" );


do{

$adid_array[] = $row[ 'id' ];
}while( $row= mysql_fetch_array($numresults));

$tmparr = array_unique($adid_array);
$i=0;
foreach ($tmparr as $v) {
$newarr[$i] = $v;
$i++;
}

while($row = mysql_fetch_array( $numresult ) or die (mysql_error())) {
echo $row['name']." - ".$row['email']. "<br />";
}
?> //Line 41

[/code][/code]

Link to comment
Share on other sites

there was no ending bracket i added it goodluck

 

<?php
@mysql_connect("mysql.x10hosting.com", "gb_GB", "********") or die(mysql_error());
@mysql_select_db("gb_USERInfo") or die(mysql_error());

session_start();

$var = @$_GET['Email'] ;

$trim = trim($var);

$array = explode(" ",$trim);

foreach ($array as $array){

if ($trim == "") {
$resultmsg = "<p>Search Error</p><p>Please enter an email...</p>" ;
}

$query = "SELECT * FROM Ysers WHERE email LIKE \"%$array%\" ORDER BY email DESC" ;
$results=mysql_query ($query) or die (mysql_error());
$row_num =mysql_num_rows ($results);
$row= mysql_fetch_array ($results);
$numresults = mysql_query ($query) or die ( "Couldn't execute query" );


do{

$adid_array[] = $row[ 'id' ];
}while( $row= mysql_fetch_array($numresults));

$tmparr = array_unique($adid_array);
$i=0;
foreach ($tmparr as $v) {
$newarr[$i] = $v;
$i++;
}

while($row = mysql_fetch_array( $numresult ) or die (mysql_error())) {
echo $row['name']." - ".$row['email']. "
";
}
}

?>

Link to comment
Share on other sites

Thankyou so much.

 

My script has no more errors, but due to cruel fate stopped working.

So I decided to start over with something simple and that didn't work.

 

<?php

@mysql_connect("mysql.x10hosting.com", "gb_GB", "************") or die(mysql_error());

@mysql_select_db("gb_USERInfo") or die(mysql_error());

 

session_start();

 

$var = $_POST['email'] ;

$trim = trim($var);

$earray = explode(" ",$trim);

 

$query = "SELECT * FROM Ysers WHERE email LIKE '%$earray%'";

$result = mysql_query($query);

echo $trim;

while($row = mysql_fetch_array( $result )) {

echo $row['email'];

echo"<br/>";

}

?>

 

It displays no errors.

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.