Log in

View Full Version : Resource ID has us stumped!


Cyricx
06-17-2004, 11:13 PM
Trying add a hack in that does user titles similiar to the way vb does, but where the user can pick the title group.

And fighting with the query....

first one I tried

// ##### Start Secondary Titles #####
$sectitle = $DB_site->query("SELECT displaytext FROM " . TABLE_PREFIX . "secondarytitle where category = $post[sectitletype] AND $post[posts] >= minposts AND $post[posts] <= maxposts");

// ##### End Secondary Title #####


Gives a Resource ID.

I tried the thing about making it query_first, but then it displays as Array =/

Any help would be appreciated :(

Would prefer to do away with the maxposts field, but have no idea how to build or execute an array :(

Velocd
06-18-2004, 03:00 PM
Use $DB_site->query() when retrieving more than 1 row from your database. This returns a MySQL resouce ID, that can be used in mysql_fetch_array() within a while loop to iterate through rows.

e.g.

$result = $DB_site->query("
SELECT displaytext
FROM " . TABLE_PREFIX . "secondarytitle
WHERE category = $post[sectitletype]
AND $post[posts] >= minposts
AND $post[posts] <= maxposts
");

while ($secondtitle = $DB_site->fetch_array($result))
{
echo $secondtitle['displaytext'];
}

$DB_site->query_first() is for retrieving just one query, and will return an array you can use.

e.g.

$secondtitle = $DB_site->query_first("
SELECT displaytext
FROM " . TABLE_PREFIX . "secondarytitle
WHERE category = $post[sectitletype]
AND $post[posts] >= minposts
AND $post[posts] <= maxposts
");

echo $secondtitle['displaytext'];

Cyricx
06-18-2004, 11:53 PM
Thank you so very very much :)