Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:44:06+00:00 2026-06-16T01:44:06+00:00

When I do this query directly from PHP my admin I got 5 results.

  • 0

When I do this query directly from PHP my admin I got 5 results.

SELECT img FROM `table`.`goog` WHERE `url` LIKE '%google.com%' and `pictureID` != 'picture_50d22657a423b6.62354164'; 

however, when my code

$sql2 = "SELECT img FROM `table`.`goog` WHERE `url` LIKE '%$url%' and `pictureID` != '$pictureID';";
    // echo $sql2;
$result2=mysql_query($sql2);
$rows2 = mysql_fetch_array($result2);

mysql_close($con);

print_r(count($rows2));

echo "<br/>";

echo $sql2;

it prints out

2 
SELECT img FROM `ashkan`.`goog` WHERE `url` LIKE '%66.228.42.45%' and `pictureID` != 'picture_50d22657a423b6.62354164';

I would also like to note that the query I run inside of php my admin is copied from what my code returns..

So, why does one returns only 2 items, and the other returns 5?

EDIT

I added the following to the bottom

var_dump($rows2);
echo "<br/>";
echo mysql_num_rows($result2);

and got this

array(2) { [0]=> string(1) "b" ["img"]=> string(1) "b" } 
5 

I have something that manually selects a row

Essentially I want to be able to do

echo $rows2[somenum]; //that some number is at random and only one at a time

however, as is, I can only access item 0 and not all five.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:44:07+00:00Added an answer on June 16, 2026 at 1:44 am

    UPDATED CODE

    Here’s your updated code:

    $mysqlQuery=mysql_query("SELECT img FROM `table`.`goog` WHERE `url` LIKE '%$url%' and `pictureID` != '$pictureID");
    $databaseArray=array();
    
    while($arrayQuery=mysql_fetch_array($mysqlQuery))
    {
        $imageName=$arrayQuery['img'];
        
        $databaseArray[]=$imageName;
    }
    
    echo "Database returned ".count($databaseArray)." rows.";
    
    print_r($databaseArray);
    
    echo $databaseArray[0]; // prints image name row 1
    echo $databaseArray[1]; // prints image name row 2
    echo $databaseArray[2]; // prints image name row 3
    // etc etc etc
    

    Old code

    Do this:

    $sql2 = "SELECT img FROM `table`.`goog` WHERE `url` LIKE '%$url%' and `pictureID` != '$pictureID';";
        // echo $sql2;
    $result2=mysql_query($sql2);
    
    while($data = mysql_fetch_array($result2))
    {
        var_dump($data);
    }
    

    mysql_fetch_array only returns one row at a time. The code above loops all the rows find in your database. If you only want to count the rows, then check mysql_num_rows() function.

    You should also use mysqli_* and not mysql_*, because it’s deprecated. Please read more at:
    http://php.net/manual/en/book.mysqli.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this query SELECT * FROM tblContracts LEFT JOIN tblPartys ON tblContracts.id = tblPartys.Contract_id INNER
This query works fine for me: $query = SELECT p.topnode_id, p.param_key, p.param_value FROM tbl_params
This query works: item = db.GqlQuery(SELECT * FROM Item WHERE CSIN = 13)[0] although
First, I'm just starting to learn MySQL with PHP. My query copy/paste directly from
I want to build a query like SELECT username from users WHERE login_attempts >
This does not work $get_data_qry = SELECT * FROM list;; $get_data_res = $db->Query($get_data_qry); $key
I've got months stored in a table like this December, August, July, etc. How
I am required to remove .php extension and query string as well from url
This query selects all the unique visitor sessions in a certain date range: select
This query takes ~4 seconds to complete: SELECT DISTINCT resources_resource.id, resources_resource.heading, resources_resource.name, resources_resource.old_name, resources_resource.clean_name,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.