DaveC426913
Programmer
Some pretty basic questions about mySQL/PHP.
I'm trying to get my head around what is getting returned from mysql_query's.
I'm sure what I'm using is terribly inefficient.
1] looping through rows:
OK, this is how I've seen it done, but I don't really understand it. The while statement is automagically incrementing by a row each time?
$sql = "SELECT `*` FROM tbl1 ORDER BY `MDate` DESC";
$resultA = mysql_query($sql);
while ($RevRow = mysql_fetch_array($resultA)) {
}
2] Just one value from one row in the db
If I just want to get a single specific value out of the my db, do I need to get an array returned every time?
$sql = "SELECT `CName` FROM tbl2 WHERE `CCount` = '".$RevRow['MCategory1']."'";
$resultB = mysql_query($sql);
$catName = mysql_result($resultB,0);
3] How many rows?
Is there a more streamlined method than this just for counting the rows I want? I don't need any data right now.
$sql = "SELECT `*` FROM tblReviewsMain WHERE `MRating` = '".$rat."'";
$resultD = mysql_query($sql);
$numRows = mysql_num_rows($resultD);
Thx.
I'm trying to get my head around what is getting returned from mysql_query's.
I'm sure what I'm using is terribly inefficient.
1] looping through rows:
OK, this is how I've seen it done, but I don't really understand it. The while statement is automagically incrementing by a row each time?
$sql = "SELECT `*` FROM tbl1 ORDER BY `MDate` DESC";
$resultA = mysql_query($sql);
while ($RevRow = mysql_fetch_array($resultA)) {
}
2] Just one value from one row in the db
If I just want to get a single specific value out of the my db, do I need to get an array returned every time?
$sql = "SELECT `CName` FROM tbl2 WHERE `CCount` = '".$RevRow['MCategory1']."'";
$resultB = mysql_query($sql);
$catName = mysql_result($resultB,0);
3] How many rows?
Is there a more streamlined method than this just for counting the rows I want? I don't need any data right now.
$sql = "SELECT `*` FROM tblReviewsMain WHERE `MRating` = '".$rat."'";
$resultD = mysql_query($sql);
$numRows = mysql_num_rows($resultD);
Thx.