MySQL Row Count PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tekhead2004
Forum Newbie
Posts: 1
Joined: Thu Feb 19, 2009 9:31 am

MySQL Row Count PHP

Post by tekhead2004 »

Hi all. Trying to figure out why my row count only returns a value of 1 although I know it should be returing more.

Code: Select all

 
$mySQL = "SELECT Pallet, puwo_number as 'Pickup Workorder', t_tag as 'T-Tag', Make, Model, serial_number as 'Serial Number' , comments as 'Comments', (Select description from dropdowns where tablename = 'pickups' and columnname = 'type' and value =pickups.type) as Type , Location, shipdate as 'Ship Date', CONCAT('<a href=http://www.fedex.com/Tracking?&cntry_code=us&clienttype=ivother&tracknumbers=' , Tracking_number,' target=new>',Tracking_number,'</a>') as 'Tracking Number', logged_by as 'Logged By', Edited_by as 'Edited By' from pickups, locations where pickups.locationid = locations.locationid";
        if (trim($_POST["criteria"]) != ""  && trim($_POST["choice"]) != "") {
            $mySQL .= " and (" . $_POST['choice'] ." = ";
            $mySQL .= " '".str_replace("\n" ,"' or ". $_POST['choice'] ."= '", trim(str_replace(", ","' or ".$_POST['choice'] ."= '", trim($_POST["criteria"]))))."')";
        }
        echo "MYSQL query made by variables: $mySQL <br><br>";
        $result = mysql_query ($mySQL) ;
        if (!$result)
        {
              die('Error: ' . mysql_error());
        }
        $count =  mysql_num_rows($result);
        
        $Output .= "Rows Returned (this using the dynamic:".$count."<br>";
 
Last edited by pickle on Fri Feb 20, 2009 11:04 am, edited 1 time in total.
Reason: Made [code][/code] tags work, changed to [code=php]
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: MySQL Row Count PHP

Post by Stryks »

Well ... are you SURE that your query is in fact returning more than one result? I cant see any looping and outputting of the results so you can be sure. Try that and see how many results show vs. how many it tells you about.
vmmene
Forum Newbie
Posts: 8
Joined: Mon Feb 09, 2009 3:26 am

Re: MySQL Row Count PHP

Post by vmmene »

echo your sql statement then run it on mysql it will give the exact results.
Post Reply