PDA

View Full Version : About mysql


keisko
08-04-2006, 01:32 PM
Hello,

What should I change in below code:
I didnt see mysql_num_rows and mysql_fetch_row functions in the mysql.php


function get_topic_forum($topicid)
**{
******global $DB;
****$res = $DB->query("SELECT forumid FROM topics WHERE id=$topicid");

****if (mysql_num_rows($res) != 1)
******return false;

****$arr = mysql_fetch_row($res);

****return $arr[0];
**}

crashnet47
08-04-2006, 06:03 PM
What exactly is your question?

mysql_num_rows() counts the number of rows queried.

mysql_fetch_row() gets the rows queried and puts them into an array that you can traverse to access the information, usually by field name, in this case "forumid" because this is the only field being selected in the query.

keisko
08-04-2006, 10:19 PM
e.g.
if (mysql_num_rows($res) !=1)

^^ should be

if ($DB->get_num_rows($res) !=1)

understood?

but I dont know how to change below code
$arr = mysql_fetch_row($res);

crashnet47
08-05-2006, 03:19 AM
Oh ok. Sorry for the confusion.


function get_topic_forum($topicid)
{
****global $DB;
****$res = $DB->query("SELECT forumid FROM topics WHERE id=$topicid");

****$topicrows = $DB->get_num_rows($res);

****if ($topicrows != 1)
****{
********return false;
****}
****
****$arr = $DB->fetch_array($res);
****return $arr[0];
}


That should do it for you. :) The function you were looking for is fetch_array().

spib
08-05-2006, 08:50 AM
Actually what he really ought to write is

function get_topic_forum($topicid)
{
****global $DB;
****$arr = $DB->query("SELECT forumid FROM topics WHERE id=$topicid");

****return $arr[0];
}

crashnet47
08-05-2006, 03:44 PM
True, that would return a false anyway if it didn't exist. But he knows about the fetch_array() function now. :)

spib
08-06-2006, 04:19 PM
sorry, my code has a mistake in it. I meant to use the query_first function

function get_topic_forum($topicid)
{
****global $DB;
****$arr = $DB->query_first("SELECT forumid FROM topics WHERE id=$topicid");

****return $arr[0];
}