MyBB Community Forums

Full Version: MySQL query for getting row id
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a MySQL query that allows you to get a row's id based on a WHERE clause? I don't mean the fid field that a forum has but the row? For example:

id--title---description
1--word-----2nd word=====First row
3--text------3rd word=====second row

You get me? It's for a topsite a list of sites are sorted based on the number of hits. A logo is on each site displaying what spot it's in first place, second etc.
SELECT * FROM `TABLE_NAME` WHERE id='id here' ;

That's for getting all of the information in the row.

SELECT id FROM `TABLE_NAME` WHERE id='id here' ;

Will only show the id of that row.
if you want to select the value of a specific row, do something like this:

$query = mysql_query($db, "SELECT * FROM `TABLE_NAME` WHERE id='id here' ;");
$rows = $db->fetch_array($query);
echo "<pre>";
print_r($rows);
echo "</pre>";

echo $row['somefieldhere'];

Or, if you want to with mybb

$query = $db->query("SELECT * FROM `TABLE_NAME` WHERE id='id here'");
$rows = $db->fetch_array($query);

echo "<pre>";
print_r($rows);
echo "</pre>";

echo $db->fetch_field($query, 'somefieldhere');
No what I'm trying to return from the database is the text in bold as an interger.
text can not be an integter. Integters are only numeric, text can be both.
Sorry, I don't understand the specific requirement here.

SELECT * FROM TABLE_NAME
Running the above query will return the rows in order they are in mysql (first to last) and just a counter in PHP loop should give the accurate row number, you don't need mysql involvement here.

$some_counter = 0;
while ($row = mysql_fetch_array($query)) {
    $some_counter++;
    echo "Row number: {$some_counter}";
}
Nevermind I figured it out