PDA

View Full Version : vB db system


Dimava
Wed 12th Jun '02, 3:00pm
I copied the vbb global.php file and i pretty much narrowed it down and got rid of all the stuff that I didn't need

now in a regular file i'm trying to use this code:

$front_page_news=$DB_site->query_first("SELECT COUNT(*) AS frontpage_news FROM news ORDER BY date DESC, id DESC LIMIT 5");


to replace:

while(list($id,$title,$date,$username,$description ,$source,$image) = mysql_fetch_row($result)){


thanks

Dimava

scoutt
Wed 12th Jun '02, 5:34pm
that can't replace that row. one is a query and the other is fetching that query.

Dimava
Wed 12th Jun '02, 5:53pm
how does vbb fetch queries

scoutt
Wed 12th Jun '02, 8:00pm
are you using the db_mysql.php file? the class it uses is in there.

Dimava
Wed 12th Jun '02, 9:16pm
yea, can you give me an example of how I would use it to return it in a normal php file

scoutt
Wed 12th Jun '02, 10:31pm
ok in your normal php file you need to define the class variable that you will use. in this case $DB_site wil be it.

$DB_site = new DBSQL();

then you need to connect to it.

$DB_site = connect();

now you can start using the class reference.

$front_page_news=$DB_site->query_first("SELECT COUNT(*) AS frontpage_news FROM news ORDER BY date DESC, id DESC LIMIT 5");

the query_first will already return a row, so you should be able to just echo it out.

echo $front_page_news['column_name'];

Dimava
Thu 13th Jun '02, 12:35am
what if it returns more than 1 row?

scoutt
Thu 13th Jun '02, 2:41am
well it could, but it says it will return the first row.

Dimava
Thu 13th Jun '02, 1:44pm
oh ok, then how could I get it to return more than 1 row

scoutt
Thu 13th Jun '02, 3:30pm
then I wouldn't use the query_first, I would use query instead. then you can use the fetch_array function the same way.

$front_page_news=$DB_site->query("SELECT COUNT(*) AS frontpage_news FROM news ORDER BY date DESC, id DESC LIMIT 5");

while($row = $DB_site->fetch_array($front_page_news)){
echo you stuff here

}

something like that