Here is a script that I typed into php MyAdmin:
SELECT
M.media_name FROM media as M
INNER JOIN member_media as J on J.mediaID = M.mediaID
WHERE J.maaMemberId = 209
The number of rows it returns is 3
Here is the php version:
$q = "SELECT
M.media_name FROM media as M
INNER JOIN member_media as J on J.mediaID = M.mediaID
WHERE J.maaMemberId = 209";
$r = @mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
$row = mysqli_fetch_array ($r, MYSQLI_NUM);
echo $row[0];
echo $row[1];
echo $row[2];
exit();
The only result is $row[0] which is a correct result (matches first row in first example)
The other 2 rows give "Undefined offset"
php myAdmin gives different results than php code in query
Moderator: General Moderators
Re: php myAdmin gives different results than php code in que
It's not giving different results, you're just handling the results incorrectly. mysql_fetch_array() returns one array per row. Wrap it in a while loop and you'll get the results you expect.
Re: php myAdmin gives different results than php code in que
I thought the array that was produced (in this case) was that of $row[0],$row[1],$row[2] where each of these three held a single row in the results of the query?
What you're saying is that:
while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) {
echo "One medium is ".$row[0]."<br />";
}
will print the entire result array within $row[0]?
and... I see that every time I have the line $row = mysqli_fetch_array($r, MYSQLI_NUM))
it eliminates one element within the array ( because it has already been "fetched")
so that if I had (even though it doesn't make sense)...
$row = mysqli_fetch_array($r, MYSQLI_NUM)
$row = mysqli_fetch_array($r, MYSQLI_NUM)
$row = mysqli_fetch_array($r, MYSQLI_NUM)
then, if I go:
while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) {
echo "One medium is ".$row[0]."<br />";
}
There will be nothing left to print out in the array within $row[0]!!
What you're saying is that:
while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) {
echo "One medium is ".$row[0]."<br />";
}
will print the entire result array within $row[0]?
and... I see that every time I have the line $row = mysqli_fetch_array($r, MYSQLI_NUM))
it eliminates one element within the array ( because it has already been "fetched")
so that if I had (even though it doesn't make sense)...
$row = mysqli_fetch_array($r, MYSQLI_NUM)
$row = mysqli_fetch_array($r, MYSQLI_NUM)
$row = mysqli_fetch_array($r, MYSQLI_NUM)
then, if I go:
while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) {
echo "One medium is ".$row[0]."<br />";
}
There will be nothing left to print out in the array within $row[0]!!
-
litebearer
- Forum Contributor
- Posts: 194
- Joined: Sat Mar 27, 2004 5:54 am
Re: php myAdmin gives different results than php code in que
test this
Code: Select all
while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) {
echo $row[0]. "<br />" . $row[1] . "<br />" . $row[2] . "<hr>";
}