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.
UPDATED CODE
Here’s your updated code:
Old code
Do this:
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