source code:
$display = 1004;
$result1 = mysql_query("SELECT id, username FROM users where parentid=$diplay");
$resrow = mysql_fetch_row($result1);
$g = $resrow[0];
$g1 = $resrow[1];
$g2 = $resrow[3]; -error not display
$g3 = $resrow[4];
$g4 = $resrow[5];
echo "ID: $g";
echo "ID: $g2";
echo "ID: $g3";
echo "ID: $g4";
i have to show 1005, 1007, 1008 but i can retrieve $g value only:
ans: 1004 daniel
how i can show other values 1007,1008
Table
id ----name ----- parentid
-----------------------------------
1004 daniel 1003
1005 peter 1004
1007 michael 1004
1008 sam 1004
ans:
$g
1004
/ \
g2 g3
1005 1007
You are confusing rows with columns. On this database:
The query
SELECT id, name FROM users where parentid=1004will return rows 1005, 1007, and 1008.mysql_fetch_row()only fetches one row at a time.That’s across (the
idandname), not down (severalids).To get a list of all of the ID values that match, you need to loop through all the rows:
As mentioned above, don’t use
ext/mysqlfor new work. I’m using it here only because that’s how you asked your original question. You need to update your code and useext/mysqliorPDOinstead.