i have a problem with while loop.In this first column data is not getting remaining data is getting
here is my code

$result_By_Vendor_And_Title = mysql_query("select * from cek6q_jshopping_products where vendor_id = " . $vendor . " and name_en-GB='" . $title . "'");

if (mysql_fetch_array($result_By_Vendor_And_Title)) {
      echo 'found';
      while ( $rows = mysql_fetch_array($result_By_Vendor_And_Title) ) {
          echo $id = $rows['product_id'];
      }
}
echo 'not found';

Here i want to display all the ids but i have getting all the ids except first one how i can get first one.

share
3  
Because the mysql_fetch_array() call that you do to test for found is fetching and discarding the first row, Use mysql_num_rows() to identify if a result has been found.... then learn about MySQLi/PDO and prepared statements/bind variables – Mark Baker Oct 1 '13 at 7:19
    
Thanks Your code is not working, i have not getting first row till now also – Durga Rao Oct 1 '13 at 7:57
    
We've explained the cause problem to you: you have two coded solutions below, both of which will work... if they're not working, then you've messed something else up.... show us your latest code – Mark Baker Oct 1 '13 at 8:02

Because the fetch_array you do to test for found is fetching and discarding the first row just try this

$result_By_Vendor_And_Title = mysql_query("select * from cek6q_jshopping_products where vendor_id = '" . $vendor . "' and name_en-GB='" . $title . "'");

if($result_By_Vendor_And_Title){
if(mysql_num_rows($result_By_Vendor_And_Title)>0){
   echo 'found';
   while ( $rows = mysql_fetch_array($result_By_Vendor_And_Title) ) { 
     echo $id = $rows['product_id'];
   }
}else{ 
    echo 'not found';
}
}
share
    
Thanks Your code is not working, i have not getting first row till now also – Durga Rao Oct 1 '13 at 7:53

Try:

if( mysql_num_rows( $result_By_Vendor_And_Title ) > 0 ) {
    echo 'found';
    while ( $rows = mysql_fetch_array($result_By_Vendor_And_Title) )
    { echo $id = $rows['product_id']; } 
}else{
    echo 'not found';   
}

Dont use mysql_* functions.

share
    
Why not to use mysql_ can u elaborate me plz – Durga Rao Oct 1 '13 at 7:27
    
Because its not secure and deprecated now. Learn MySQLi/PDO. There are numerous tutorials on web. Did it solved your query? – Nil'z Oct 1 '13 at 7:29
    
The mysql_* library is deprecated as of PHP 5.5.0. So if you are upgrading your PHP in future, this application wont work. – Saravanan Oct 1 '13 at 7:32
    
Thanks Your code is not working, i have not getting first row till now also – Durga Rao Oct 1 '13 at 7:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.